2025-04-17 20:55:27 +05:30
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
|
import 'package:immich_mobile/domain/utils/background_sync.dart';
|
2025-10-03 19:06:44 +05:30
|
|
|
import 'package:immich_mobile/providers/backup/drift_backup.provider.dart';
|
2025-07-18 08:39:28 -05:00
|
|
|
import 'package:immich_mobile/providers/sync_status.provider.dart';
|
2025-04-17 20:55:27 +05:30
|
|
|
|
|
|
|
|
final backgroundSyncProvider = Provider<BackgroundSyncManager>((ref) {
|
2025-07-18 08:39:28 -05:00
|
|
|
final syncStatusNotifier = ref.read(syncStatusProvider.notifier);
|
2025-10-03 19:06:44 +05:30
|
|
|
final backupProvider = ref.read(driftBackupProvider.notifier);
|
|
|
|
|
|
2025-07-18 08:39:28 -05:00
|
|
|
final manager = BackgroundSyncManager(
|
2025-10-03 19:06:44 +05:30
|
|
|
onRemoteSyncStart: () {
|
|
|
|
|
syncStatusNotifier.startRemoteSync();
|
|
|
|
|
backupProvider.updateError(BackupError.none);
|
|
|
|
|
},
|
|
|
|
|
onRemoteSyncComplete: (isSuccess) {
|
|
|
|
|
syncStatusNotifier.completeRemoteSync();
|
|
|
|
|
backupProvider.updateError(isSuccess == true ? BackupError.none : BackupError.syncFailed);
|
|
|
|
|
},
|
2025-07-18 08:39:28 -05:00
|
|
|
onRemoteSyncError: syncStatusNotifier.errorRemoteSync,
|
2025-07-22 11:24:32 -05:00
|
|
|
onLocalSyncStart: syncStatusNotifier.startLocalSync,
|
|
|
|
|
onLocalSyncComplete: syncStatusNotifier.completeLocalSync,
|
|
|
|
|
onLocalSyncError: syncStatusNotifier.errorLocalSync,
|
|
|
|
|
onHashingStart: syncStatusNotifier.startHashJob,
|
|
|
|
|
onHashingComplete: syncStatusNotifier.completeHashJob,
|
|
|
|
|
onHashingError: syncStatusNotifier.errorHashJob,
|
2025-07-18 08:39:28 -05:00
|
|
|
);
|
2025-04-17 20:55:27 +05:30
|
|
|
ref.onDispose(manager.cancel);
|
|
|
|
|
return manager;
|
|
|
|
|
});
|