From 5172242f88b204e78fd92a5749358d243738ae30 Mon Sep 17 00:00:00 2001 From: Fynn Petersen-Frey Date: Tue, 30 Aug 2022 16:09:19 +0200 Subject: [PATCH] fix: persist WiFi + charging settings of background backup (#553) --- mobile/lib/constants/hive_box.dart | 4 +++- .../backup/providers/backup.provider.dart | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mobile/lib/constants/hive_box.dart b/mobile/lib/constants/hive_box.dart index d422af08f2..7faf6555f6 100644 --- a/mobile/lib/constants/hive_box.dart +++ b/mobile/lib/constants/hive_box.dart @@ -22,4 +22,6 @@ const String userSettingInfoBox = "immichUserSettingInfoBox"; // Background backup Info const String backgroundBackupInfoBox = "immichBackgroundBackupInfoBox"; // Box -const String backupFailedSince = "immichBackupFailedSince"; // Key 1 \ No newline at end of file +const String backupFailedSince = "immichBackupFailedSince"; // Key 1 +const String backupRequireWifi = "immichBackupRequireWifi"; // Key 2 +const String backupRequireCharging = "immichBackupRequireCharging"; // Key 3 diff --git a/mobile/lib/modules/backup/providers/backup.provider.dart b/mobile/lib/modules/backup/providers/backup.provider.dart index baf66ea417..37082bfe98 100644 --- a/mobile/lib/modules/backup/providers/backup.provider.dart +++ b/mobile/lib/modules/backup/providers/backup.provider.dart @@ -138,7 +138,12 @@ class BackupNotifier extends StateNotifier { requireUnmetered: state.backupRequireWifi, requireCharging: state.backupRequireCharging, ); - if (!success) { + if (success) { + await Hive.box(backgroundBackupInfoBox) + .put(backupRequireWifi, state.backupRequireWifi); + await Hive.box(backgroundBackupInfoBox) + .put(backupRequireCharging, state.backupRequireCharging); + } else { state = state.copyWith( backgroundBackup: wasEnabled, backupRequireWifi: wasWifi, @@ -549,10 +554,13 @@ class BackupNotifier extends StateNotifier { albums.lastExcludedBackupTime, ); } + final Box backgroundBox = await Hive.openBox(backgroundBackupInfoBox); state = state.copyWith( backupProgress: previous, selectedBackupAlbums: selectedAlbums, excludedBackupAlbums: excludedAlbums, + backupRequireWifi: backgroundBox.get(backupRequireWifi), + backupRequireCharging: backgroundBox.get(backupRequireCharging), ); } return _resumeBackup(); @@ -590,6 +598,13 @@ class BackupNotifier extends StateNotifier { } catch (error) { debugPrint("[_notifyBackgroundServiceCanRun] failed to close box"); } + try { + if (Hive.isBoxOpen(backgroundBackupInfoBox)) { + await Hive.box(backgroundBackupInfoBox).close(); + } + } catch (error) { + debugPrint("[_notifyBackgroundServiceCanRun] failed to close box"); + } _backgroundService.releaseLock(); } }