From fdc5349059a5e5c919871f60579a1854e88a03f8 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 6 Dec 2023 15:55:59 -0600 Subject: [PATCH] handle ingore iCloud asset upload' --- .../backup/services/backup.service.dart | 14 +++++++++- .../backup/views/backup_options_page.dart | 28 ++++++++++++++++++- .../services/app_settings.service.dart | 1 + mobile/lib/shared/models/store.dart | 1 + 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/mobile/lib/modules/backup/services/backup.service.dart b/mobile/lib/modules/backup/services/backup.service.dart index 3df9e4476..e71e171f9 100644 --- a/mobile/lib/modules/backup/services/backup.service.dart +++ b/mobile/lib/modules/backup/services/backup.service.dart @@ -10,6 +10,8 @@ import 'package:immich_mobile/modules/backup/models/backup_album.model.dart'; import 'package:immich_mobile/modules/backup/models/current_upload_asset.model.dart'; import 'package:immich_mobile/modules/backup/models/duplicated_asset.model.dart'; import 'package:immich_mobile/modules/backup/models/error_upload_asset.model.dart'; +import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart'; +import 'package:immich_mobile/modules/settings/services/app_settings.service.dart'; import 'package:immich_mobile/shared/models/store.dart'; import 'package:immich_mobile/shared/providers/api.provider.dart'; import 'package:immich_mobile/shared/providers/db.provider.dart'; @@ -26,6 +28,7 @@ final backupServiceProvider = Provider( (ref) => BackupService( ref.watch(apiServiceProvider), ref.watch(dbProvider), + ref.watch(appSettingsServiceProvider), ), ); @@ -34,8 +37,9 @@ class BackupService { final ApiService _apiService; final Isar _db; final Logger _log = Logger("BackupService"); + final AppSettingsService _appSetting; - BackupService(this._apiService, this._db); + BackupService(this._apiService, this._db, this._appSetting); Future?> getDeviceBackupAsset() async { final String deviceId = Store.get(StoreKey.deviceId); @@ -209,6 +213,9 @@ class BackupService { Function(ErrorUploadAsset) errorCb, { bool sortAssets = false, }) async { + final bool isIgnoreIcloudAssets = + _appSetting.getSetting(AppSettingsEnum.ignoreIcloudAssets); + if (Platform.isAndroid && !(await Permission.accessMediaLocation.status).isGranted) { // double check that permission is granted here, to guard against @@ -246,6 +253,11 @@ class BackupService { // Handle getting files from iCloud if (!isAvailableLocally && Platform.isIOS) { + // Skip iCloud assets if the user has disabled this feature + if (isIgnoreIcloudAssets) { + continue; + } + setCurrentUploadAssetCb( CurrentUploadAsset( id: entity.id, diff --git a/mobile/lib/modules/backup/views/backup_options_page.dart b/mobile/lib/modules/backup/views/backup_options_page.dart index 5d86be159..8741ca837 100644 --- a/mobile/lib/modules/backup/views/backup_options_page.dart +++ b/mobile/lib/modules/backup/views/backup_options_page.dart @@ -31,6 +31,9 @@ class BackupOptionsPage extends HookConsumerWidget { final settingsService = ref.watch(appSettingsServiceProvider); final showBackupFix = Platform.isAndroid && settingsService.getSetting(AppSettingsEnum.advancedTroubleshooting); + final ignoreIcloudAssets = useState( + settingsService.getSetting(AppSettingsEnum.ignoreIcloudAssets), + ); final appRefreshDisabled = Platform.isIOS && settings?.appRefreshEnabled != true; final checkInProgress = useState(false); @@ -433,7 +436,6 @@ class BackupOptionsPage extends HookConsumerWidget { if (!isAutoBackup) const Text( "backup_controller_page_desc_backup", - style: TextStyle(fontSize: 14), ).tr(), Padding( padding: const EdgeInsets.only(top: 8.0), @@ -455,6 +457,29 @@ class BackupOptionsPage extends HookConsumerWidget { ); } + void switchChanged(bool value) { + settingsService.setSetting(AppSettingsEnum.ignoreIcloudAssets, value); + ignoreIcloudAssets.value = value; + ref.invalidate(appSettingsServiceProvider); + } + + buildIgnoreIcloudAssetSetting() { + return [ + const Divider(), + SwitchListTile.adaptive( + title: const Text( + "Ignore iCloud photos", + style: TextStyle(fontWeight: FontWeight.bold), + ), + subtitle: const Text( + "Photos that are stored on iCloud will not be uploaded to the Immich server", + ), + value: ignoreIcloudAssets.value, + onChanged: switchChanged, + ), + ]; + } + return Scaffold( appBar: AppBar( elevation: 0, @@ -487,6 +512,7 @@ class BackupOptionsPage extends HookConsumerWidget { ), if (showBackupFix) const Divider(), if (showBackupFix) buildCheckCorruptBackups(), + if (Platform.isIOS) ...buildIgnoreIcloudAssetSetting(), ], ), ), diff --git a/mobile/lib/modules/settings/services/app_settings.service.dart b/mobile/lib/modules/settings/services/app_settings.service.dart index 657e916bf..509dd5a93 100644 --- a/mobile/lib/modules/settings/services/app_settings.service.dart +++ b/mobile/lib/modules/settings/services/app_settings.service.dart @@ -51,6 +51,7 @@ enum AppSettingsEnum { mapIncludeArchived(StoreKey.mapIncludeArchived, null, false), mapRelativeDate(StoreKey.mapRelativeDate, null, 0), allowSelfSignedSSLCert(StoreKey.selfSignedCert, null, false), + ignoreIcloudAssets(StoreKey.ignoreIcloudAssets, null, false), ; const AppSettingsEnum(this.storeKey, this.hiveKey, this.defaultValue); diff --git a/mobile/lib/shared/models/store.dart b/mobile/lib/shared/models/store.dart index 8a186af9a..7887f7255 100644 --- a/mobile/lib/shared/models/store.dart +++ b/mobile/lib/shared/models/store.dart @@ -182,6 +182,7 @@ enum StoreKey { mapRelativeDate(119, type: int), selfSignedCert(120, type: bool), mapIncludeArchived(121, type: bool), + ignoreIcloudAssets(122, type: bool), ; const StoreKey(