mirror of
https://github.com/immich-app/immich.git
synced 2025-09-29 15:31:13 -04:00
chore: do not remote sync twice in backup page (#22484)
do not remote sync twice in backup page Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
75b9bd163e
commit
44284b4351
@ -599,7 +599,7 @@
|
|||||||
"backup_controller_page_turn_on": "Turn on foreground backup",
|
"backup_controller_page_turn_on": "Turn on foreground backup",
|
||||||
"backup_controller_page_uploading_file_info": "Uploading file info",
|
"backup_controller_page_uploading_file_info": "Uploading file info",
|
||||||
"backup_err_only_album": "Cannot remove the only album",
|
"backup_err_only_album": "Cannot remove the only album",
|
||||||
"backup_error_sync_failed": "Sync failed. Cannot start backup.",
|
"backup_error_sync_failed": "Sync failed. Cannot process backup.",
|
||||||
"backup_info_card_assets": "assets",
|
"backup_info_card_assets": "assets",
|
||||||
"backup_manual_cancelled": "Cancelled",
|
"backup_manual_cancelled": "Cancelled",
|
||||||
"backup_manual_in_progress": "Upload already in progress. Try after sometime",
|
"backup_manual_in_progress": "Upload already in progress. Try after sometime",
|
||||||
|
@ -31,6 +31,8 @@ class DriftBackupPage extends ConsumerStatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _DriftBackupPageState extends ConsumerState<DriftBackupPage> {
|
class _DriftBackupPageState extends ConsumerState<DriftBackupPage> {
|
||||||
|
bool? syncSuccess;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -44,7 +46,13 @@ class _DriftBackupPageState extends ConsumerState<DriftBackupPage> {
|
|||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
await ref.read(driftBackupProvider.notifier).getBackupStatus(currentUser.id);
|
await ref.read(driftBackupProvider.notifier).getBackupStatus(currentUser.id);
|
||||||
await ref.read(backgroundSyncProvider).syncRemote();
|
|
||||||
|
ref.read(driftBackupProvider.notifier).updateSyncing(true);
|
||||||
|
syncSuccess = await ref.read(backgroundSyncProvider).syncRemote();
|
||||||
|
ref
|
||||||
|
.read(driftBackupProvider.notifier)
|
||||||
|
.updateError(syncSuccess == true ? BackupError.none : BackupError.syncFailed);
|
||||||
|
ref.read(driftBackupProvider.notifier).updateSyncing(false);
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
await ref.read(driftBackupProvider.notifier).getBackupStatus(currentUser.id);
|
await ref.read(driftBackupProvider.notifier).getBackupStatus(currentUser.id);
|
||||||
@ -76,12 +84,17 @@ class _DriftBackupPageState extends ConsumerState<DriftBackupPage> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final syncSuccess = await backupSyncManager.syncRemote();
|
if (syncSuccess == null) {
|
||||||
|
ref.read(driftBackupProvider.notifier).updateSyncing(true);
|
||||||
|
syncSuccess = await backupSyncManager.syncRemote();
|
||||||
|
ref.read(driftBackupProvider.notifier).updateSyncing(false);
|
||||||
|
}
|
||||||
|
|
||||||
await backupNotifier.getBackupStatus(currentUser.id);
|
await backupNotifier.getBackupStatus(currentUser.id);
|
||||||
|
|
||||||
if (!syncSuccess) {
|
if (syncSuccess == false) {
|
||||||
Logger("DriftBackupPage").warning("Remote sync did not complete successfully, skipping backup");
|
Logger("DriftBackupPage").warning("Remote sync did not complete successfully, skipping backup");
|
||||||
await backupNotifier.updateError(BackupError.syncFailed);
|
backupNotifier.updateError(BackupError.syncFailed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await backupNotifier.startBackup(currentUser.id);
|
await backupNotifier.startBackup(currentUser.id);
|
||||||
@ -125,7 +138,13 @@ class _DriftBackupPageState extends ConsumerState<DriftBackupPage> {
|
|||||||
const _BackupCard(),
|
const _BackupCard(),
|
||||||
const _RemainderCard(),
|
const _RemainderCard(),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
BackupToggleButton(onStart: () async => await startBackup(), onStop: () async => await stopBackup()),
|
BackupToggleButton(
|
||||||
|
onStart: () async => await startBackup(),
|
||||||
|
onStop: () async {
|
||||||
|
syncSuccess = null;
|
||||||
|
await stopBackup();
|
||||||
|
},
|
||||||
|
),
|
||||||
switch (error) {
|
switch (error) {
|
||||||
BackupError.none => const SizedBox.shrink(),
|
BackupError.none => const SizedBox.shrink(),
|
||||||
BackupError.syncFailed => Padding(
|
BackupError.syncFailed => Padding(
|
||||||
|
@ -65,7 +65,9 @@ class BackupToggleButtonState extends ConsumerState<BackupToggleButton> with Sin
|
|||||||
|
|
||||||
final uploadTasks = ref.watch(driftBackupProvider.select((state) => state.uploadItems));
|
final uploadTasks = ref.watch(driftBackupProvider.select((state) => state.uploadItems));
|
||||||
|
|
||||||
final isUploading = uploadTasks.isNotEmpty;
|
final isSyncing = ref.watch(driftBackupProvider.select((state) => state.isSyncing));
|
||||||
|
|
||||||
|
final isProcessing = uploadTasks.isNotEmpty || isSyncing;
|
||||||
|
|
||||||
return AnimatedBuilder(
|
return AnimatedBuilder(
|
||||||
animation: _animationController,
|
animation: _animationController,
|
||||||
@ -129,7 +131,7 @@ class BackupToggleButtonState extends ConsumerState<BackupToggleButton> with Sin
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: isUploading
|
child: isProcessing
|
||||||
? const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2))
|
? const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2))
|
||||||
: Icon(Icons.cloud_upload_outlined, color: context.primaryColor, size: 24),
|
: Icon(Icons.cloud_upload_outlined, color: context.primaryColor, size: 24),
|
||||||
),
|
),
|
||||||
|
@ -109,6 +109,7 @@ class DriftBackupState {
|
|||||||
final int enqueueCount;
|
final int enqueueCount;
|
||||||
final int enqueueTotalCount;
|
final int enqueueTotalCount;
|
||||||
|
|
||||||
|
final bool isSyncing;
|
||||||
final bool isCanceling;
|
final bool isCanceling;
|
||||||
final BackupError error;
|
final BackupError error;
|
||||||
|
|
||||||
@ -122,6 +123,7 @@ class DriftBackupState {
|
|||||||
required this.enqueueCount,
|
required this.enqueueCount,
|
||||||
required this.enqueueTotalCount,
|
required this.enqueueTotalCount,
|
||||||
required this.isCanceling,
|
required this.isCanceling,
|
||||||
|
required this.isSyncing,
|
||||||
required this.uploadItems,
|
required this.uploadItems,
|
||||||
this.error = BackupError.none,
|
this.error = BackupError.none,
|
||||||
});
|
});
|
||||||
@ -134,6 +136,7 @@ class DriftBackupState {
|
|||||||
int? enqueueCount,
|
int? enqueueCount,
|
||||||
int? enqueueTotalCount,
|
int? enqueueTotalCount,
|
||||||
bool? isCanceling,
|
bool? isCanceling,
|
||||||
|
bool? isSyncing,
|
||||||
Map<String, DriftUploadStatus>? uploadItems,
|
Map<String, DriftUploadStatus>? uploadItems,
|
||||||
BackupError? error,
|
BackupError? error,
|
||||||
}) {
|
}) {
|
||||||
@ -145,6 +148,7 @@ class DriftBackupState {
|
|||||||
enqueueCount: enqueueCount ?? this.enqueueCount,
|
enqueueCount: enqueueCount ?? this.enqueueCount,
|
||||||
enqueueTotalCount: enqueueTotalCount ?? this.enqueueTotalCount,
|
enqueueTotalCount: enqueueTotalCount ?? this.enqueueTotalCount,
|
||||||
isCanceling: isCanceling ?? this.isCanceling,
|
isCanceling: isCanceling ?? this.isCanceling,
|
||||||
|
isSyncing: isSyncing ?? this.isSyncing,
|
||||||
uploadItems: uploadItems ?? this.uploadItems,
|
uploadItems: uploadItems ?? this.uploadItems,
|
||||||
error: error ?? this.error,
|
error: error ?? this.error,
|
||||||
);
|
);
|
||||||
@ -152,7 +156,7 @@ class DriftBackupState {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'DriftBackupState(totalCount: $totalCount, backupCount: $backupCount, remainderCount: $remainderCount, processingCount: $processingCount, enqueueCount: $enqueueCount, enqueueTotalCount: $enqueueTotalCount, isCanceling: $isCanceling, uploadItems: $uploadItems, error: $error)';
|
return 'DriftBackupState(totalCount: $totalCount, backupCount: $backupCount, remainderCount: $remainderCount, processingCount: $processingCount, enqueueCount: $enqueueCount, enqueueTotalCount: $enqueueTotalCount, isCanceling: $isCanceling, isSyncing: $isSyncing, uploadItems: $uploadItems, error: $error)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -167,6 +171,7 @@ class DriftBackupState {
|
|||||||
other.enqueueCount == enqueueCount &&
|
other.enqueueCount == enqueueCount &&
|
||||||
other.enqueueTotalCount == enqueueTotalCount &&
|
other.enqueueTotalCount == enqueueTotalCount &&
|
||||||
other.isCanceling == isCanceling &&
|
other.isCanceling == isCanceling &&
|
||||||
|
other.isSyncing == isSyncing &&
|
||||||
mapEquals(other.uploadItems, uploadItems) &&
|
mapEquals(other.uploadItems, uploadItems) &&
|
||||||
other.error == error;
|
other.error == error;
|
||||||
}
|
}
|
||||||
@ -180,6 +185,7 @@ class DriftBackupState {
|
|||||||
enqueueCount.hashCode ^
|
enqueueCount.hashCode ^
|
||||||
enqueueTotalCount.hashCode ^
|
enqueueTotalCount.hashCode ^
|
||||||
isCanceling.hashCode ^
|
isCanceling.hashCode ^
|
||||||
|
isSyncing.hashCode ^
|
||||||
uploadItems.hashCode ^
|
uploadItems.hashCode ^
|
||||||
error.hashCode;
|
error.hashCode;
|
||||||
}
|
}
|
||||||
@ -200,6 +206,7 @@ class DriftBackupNotifier extends StateNotifier<DriftBackupState> {
|
|||||||
enqueueCount: 0,
|
enqueueCount: 0,
|
||||||
enqueueTotalCount: 0,
|
enqueueTotalCount: 0,
|
||||||
isCanceling: false,
|
isCanceling: false,
|
||||||
|
isSyncing: false,
|
||||||
uploadItems: {},
|
uploadItems: {},
|
||||||
error: BackupError.none,
|
error: BackupError.none,
|
||||||
),
|
),
|
||||||
@ -335,10 +342,14 @@ class DriftBackupNotifier extends StateNotifier<DriftBackupState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateError(BackupError error) async {
|
void updateError(BackupError error) async {
|
||||||
state = state.copyWith(error: error);
|
state = state.copyWith(error: error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateSyncing(bool isSyncing) async {
|
||||||
|
state = state.copyWith(isSyncing: isSyncing);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> startBackup(String userId) {
|
Future<void> startBackup(String userId) {
|
||||||
state = state.copyWith(error: BackupError.none);
|
state = state.copyWith(error: BackupError.none);
|
||||||
return _uploadService.startBackup(userId, _updateEnqueueCount);
|
return _uploadService.startBackup(userId, _updateEnqueueCount);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user