Skip to content

High performance self-hosted photo and video management solution.

fix: persist WiFi + charging settings of background backup (#553)

Fynn Petersen-Frey5172242f88b2
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<BackUpState> {
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<BackUpState> {
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<BackUpState> {
} 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();
}
}