mirror of
				https://github.com/KevinMidboe/immich.git
				synced 2025-10-29 17:40:28 +00:00 
			
		
		
		
	fix: persist WiFi + charging settings of background backup (#553)
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							25e68cf826
						
					
				
				
					commit
					5172242f88
				
			@@ -22,4 +22,6 @@ const String userSettingInfoBox = "immichUserSettingInfoBox";
 | 
			
		||||
 | 
			
		||||
// Background backup Info
 | 
			
		||||
const String backgroundBackupInfoBox = "immichBackgroundBackupInfoBox"; // Box
 | 
			
		||||
const String backupFailedSince = "immichBackupFailedSince"; // Key 1
 | 
			
		||||
const String backupFailedSince = "immichBackupFailedSince"; // Key 1
 | 
			
		||||
const String backupRequireWifi = "immichBackupRequireWifi"; // Key 2
 | 
			
		||||
const String backupRequireCharging = "immichBackupRequireCharging"; // Key 3
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user