Don't do the client side fallback if it's disabled in pref

This commit is contained in:
Ming Ming 2024-11-23 23:18:23 +08:00
parent ef67d414fd
commit cfae5d6b90
5 changed files with 36 additions and 9 deletions

View file

@ -108,6 +108,7 @@ class AccountController {
KiwiContainer().resolve(), KiwiContainer().resolve(),
account: account, account: account,
prefController: prefController, prefController: prefController,
serverController: serverController,
); );
PrefController prefController; PrefController prefController;

View file

@ -3,6 +3,7 @@ import 'dart:async';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart'; import 'package:nc_photos/account.dart';
import 'package:nc_photos/controller/pref_controller.dart'; import 'package:nc_photos/controller/pref_controller.dart';
import 'package:nc_photos/controller/server_controller.dart';
import 'package:nc_photos/db/entity_converter.dart'; import 'package:nc_photos/db/entity_converter.dart';
import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/file_util.dart' as file_util;
@ -17,6 +18,7 @@ class MetadataController {
this._c, { this._c, {
required this.account, required this.account,
required this.prefController, required this.prefController,
required this.serverController,
}) { }) {
_subscriptions.add( _subscriptions.add(
prefController.isEnableClientExifChange.listen(_onSetEnableClientExif)); prefController.isEnableClientExifChange.listen(_onSetEnableClientExif));
@ -44,7 +46,12 @@ class MetadataController {
void kickstart() { void kickstart() {
_log.info("[kickstart] Metadata controller enabled"); _log.info("[kickstart] Metadata controller enabled");
_isEnable = true; _isEnable = true;
if (prefController.isEnableClientExifValue && !_hasStarted) { // on NC28+, the service is needed to get metadata for files that are not
// yet available the moment we queried them, and files not supported by the
// server (if client side exif enabled).
if ((serverController.isSupported(ServerFeature.ncMetadata) ||
prefController.isEnableClientExifValue) &&
!_hasStarted) {
_startMetadataTask(); _startMetadataTask();
} }
} }
@ -72,7 +79,7 @@ class MetadataController {
); );
_log.info("[_startMetadataTask] Missing count: $missingCount"); _log.info("[_startMetadataTask] Missing count: $missingCount");
if (missingCount > 0) { if (missingCount > 0) {
unawaited(service.startService()); unawaited(service.startService(prefController: prefController));
} }
} catch (e, stackTrace) { } catch (e, stackTrace) {
_log.shout( _log.shout(
@ -87,6 +94,7 @@ class MetadataController {
final DiContainer _c; final DiContainer _c;
final Account account; final Account account;
final PrefController prefController; final PrefController prefController;
final ServerController serverController;
final _subscriptions = <StreamSubscription>[]; final _subscriptions = <StreamSubscription>[];
var _isEnable = false; var _isEnable = false;

View file

@ -2,14 +2,22 @@ part of 'service.dart';
class ServiceConfig { class ServiceConfig {
static Future<bool> isProcessExifWifiOnly() async { static Future<bool> isProcessExifWifiOnly() async {
return Preference.getBool(_pref, _prefProcessWifiOnly, true) return Preference.getBool(_pref, _prefProcessWifiOnly, true).notNull();
.notNull();
} }
static Future<void> setProcessExifWifiOnly(bool flag) async { static Future<void> setProcessExifWifiOnly(bool flag) async {
await Preference.setBool(_pref, _prefProcessWifiOnly, flag); await Preference.setBool(_pref, _prefProcessWifiOnly, flag);
} }
static Future<bool> isEnableClientExif() async {
return Preference.getBool(_pref, _prefIsEnableClientExif, false).notNull();
}
static Future<void> setEnableClientExif(bool flag) async {
await Preference.setBool(_pref, _prefIsEnableClientExif, flag);
}
static const _pref = "service"; static const _pref = "service";
static const _prefProcessWifiOnly = "shouldProcessWifiOnly"; static const _prefProcessWifiOnly = "shouldProcessWifiOnly";
static const _prefIsEnableClientExif = "isEnableClientExif";
} }

View file

@ -28,7 +28,9 @@ part 'l10n.dart';
part 'service.g.dart'; part 'service.g.dart';
/// Start the background service /// Start the background service
Future<void> startService() async { Future<void> startService({
required PrefController prefController,
}) async {
_$__NpLog.log.info("[startService] Starting service"); _$__NpLog.log.info("[startService] Starting service");
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
await service.configure( await service.configure(
@ -46,7 +48,9 @@ Future<void> startService() async {
); );
// sync settings // sync settings
await ServiceConfig.setProcessExifWifiOnly( await ServiceConfig.setProcessExifWifiOnly(
Pref().shouldProcessExifWifiOnlyOr()); prefController.shouldProcessExifWifiOnlyValue);
await ServiceConfig.setEnableClientExif(
prefController.isEnableClientExifValue);
await service.start(); await service.start();
} }

View file

@ -41,12 +41,18 @@ class _SyncByServer {
_log.fine("[_syncDir] Syncing dir $dir"); _log.fine("[_syncDir] Syncing dir $dir");
final files = await fileRepoRemote.list(account, dir); final files = await fileRepoRemote.list(account, dir);
await FileSqliteCacheUpdater(db)(account, dir, remote: files); await FileSqliteCacheUpdater(db)(account, dir, remote: files);
final isEnableClientExif = await ServiceConfig.isEnableClientExif();
for (final f in files.where((e) => fileIds.contains(e.fdId))) { for (final f in files.where((e) => fileIds.contains(e.fdId))) {
File? result; File? result;
if (!_supportedMimes.contains(f.fdMime)) { if (!_supportedMimes.contains(f.fdMime)) {
_log.info( if (isEnableClientExif) {
"[_syncDir] File ${f.path} (mime: ${f.fdMime}) not supported by server, fallback to client"); _log.info(
result = await fallback.syncOne(f); "[_syncDir] File ${f.path} (mime: ${f.fdMime}) not supported by server, fallback to client");
result = await fallback.syncOne(f);
} else {
_log.info(
"[_syncDir] File ${f.path} (mime: ${f.fdMime}) not supported by server");
}
} else { } else {
if (f.metadata != null && f.location == null) { if (f.metadata != null && f.location == null) {
result = await _syncOne(f); result = await _syncOne(f);