From cfae5d6b900a47719eec012f190be9ca59394dc8 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Sat, 23 Nov 2024 23:18:23 +0800 Subject: [PATCH] Don't do the client side fallback if it's disabled in pref --- app/lib/controller/account_controller.dart | 1 + app/lib/controller/metadata_controller.dart | 12 ++++++++++-- app/lib/service/config.dart | 12 ++++++++++-- app/lib/service/service.dart | 8 ++++++-- app/lib/use_case/sync_metadata/sync_by_server.dart | 12 +++++++++--- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/app/lib/controller/account_controller.dart b/app/lib/controller/account_controller.dart index 91436c43..695bb483 100644 --- a/app/lib/controller/account_controller.dart +++ b/app/lib/controller/account_controller.dart @@ -108,6 +108,7 @@ class AccountController { KiwiContainer().resolve(), account: account, prefController: prefController, + serverController: serverController, ); PrefController prefController; diff --git a/app/lib/controller/metadata_controller.dart b/app/lib/controller/metadata_controller.dart index 24e55336..68111347 100644 --- a/app/lib/controller/metadata_controller.dart +++ b/app/lib/controller/metadata_controller.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:logging/logging.dart'; import 'package:nc_photos/account.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/di_container.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; @@ -17,6 +18,7 @@ class MetadataController { this._c, { required this.account, required this.prefController, + required this.serverController, }) { _subscriptions.add( prefController.isEnableClientExifChange.listen(_onSetEnableClientExif)); @@ -44,7 +46,12 @@ class MetadataController { void kickstart() { _log.info("[kickstart] Metadata controller enabled"); _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(); } } @@ -72,7 +79,7 @@ class MetadataController { ); _log.info("[_startMetadataTask] Missing count: $missingCount"); if (missingCount > 0) { - unawaited(service.startService()); + unawaited(service.startService(prefController: prefController)); } } catch (e, stackTrace) { _log.shout( @@ -87,6 +94,7 @@ class MetadataController { final DiContainer _c; final Account account; final PrefController prefController; + final ServerController serverController; final _subscriptions = []; var _isEnable = false; diff --git a/app/lib/service/config.dart b/app/lib/service/config.dart index 67690b77..b0fe3fd8 100644 --- a/app/lib/service/config.dart +++ b/app/lib/service/config.dart @@ -2,14 +2,22 @@ part of 'service.dart'; class ServiceConfig { static Future isProcessExifWifiOnly() async { - return Preference.getBool(_pref, _prefProcessWifiOnly, true) - .notNull(); + return Preference.getBool(_pref, _prefProcessWifiOnly, true).notNull(); } static Future setProcessExifWifiOnly(bool flag) async { await Preference.setBool(_pref, _prefProcessWifiOnly, flag); } + static Future isEnableClientExif() async { + return Preference.getBool(_pref, _prefIsEnableClientExif, false).notNull(); + } + + static Future setEnableClientExif(bool flag) async { + await Preference.setBool(_pref, _prefIsEnableClientExif, flag); + } + static const _pref = "service"; static const _prefProcessWifiOnly = "shouldProcessWifiOnly"; + static const _prefIsEnableClientExif = "isEnableClientExif"; } diff --git a/app/lib/service/service.dart b/app/lib/service/service.dart index b06da03f..83813b21 100644 --- a/app/lib/service/service.dart +++ b/app/lib/service/service.dart @@ -28,7 +28,9 @@ part 'l10n.dart'; part 'service.g.dart'; /// Start the background service -Future startService() async { +Future startService({ + required PrefController prefController, +}) async { _$__NpLog.log.info("[startService] Starting service"); final service = FlutterBackgroundService(); await service.configure( @@ -46,7 +48,9 @@ Future startService() async { ); // sync settings await ServiceConfig.setProcessExifWifiOnly( - Pref().shouldProcessExifWifiOnlyOr()); + prefController.shouldProcessExifWifiOnlyValue); + await ServiceConfig.setEnableClientExif( + prefController.isEnableClientExifValue); await service.start(); } diff --git a/app/lib/use_case/sync_metadata/sync_by_server.dart b/app/lib/use_case/sync_metadata/sync_by_server.dart index 66ed17a6..12b27608 100644 --- a/app/lib/use_case/sync_metadata/sync_by_server.dart +++ b/app/lib/use_case/sync_metadata/sync_by_server.dart @@ -41,12 +41,18 @@ class _SyncByServer { _log.fine("[_syncDir] Syncing dir $dir"); final files = await fileRepoRemote.list(account, dir); await FileSqliteCacheUpdater(db)(account, dir, remote: files); + final isEnableClientExif = await ServiceConfig.isEnableClientExif(); for (final f in files.where((e) => fileIds.contains(e.fdId))) { File? result; if (!_supportedMimes.contains(f.fdMime)) { - _log.info( - "[_syncDir] File ${f.path} (mime: ${f.fdMime}) not supported by server, fallback to client"); - result = await fallback.syncOne(f); + if (isEnableClientExif) { + _log.info( + "[_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 { if (f.metadata != null && f.location == null) { result = await _syncOne(f);