mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
fix: _safeRun is finally safe (#30571)
Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
1a40ef66b4
commit
555fbde840
1 changed files with 10 additions and 8 deletions
|
|
@ -93,13 +93,13 @@ class AppLifeCycleNotifier extends StateNotifier<AppLifeCycleEnum> {
|
||||||
await _ref.read(galleryPermissionNotifier.notifier).getGalleryPermissionStatus();
|
await _ref.read(galleryPermissionNotifier.notifier).getGalleryPermissionStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _safeRun(Future<void> action, String debugName) async {
|
Future<void> _safeRun(Future<void> Function() action, String debugName) async {
|
||||||
if (!_shouldContinueOperation()) {
|
if (!_shouldContinueOperation()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await action;
|
await action();
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
_log.warning("Error during $debugName operation", e, stackTrace);
|
_log.warning("Error during $debugName operation", e, stackTrace);
|
||||||
}
|
}
|
||||||
|
|
@ -117,13 +117,15 @@ class AppLifeCycleNotifier extends StateNotifier<AppLifeCycleEnum> {
|
||||||
try {
|
try {
|
||||||
bool syncSuccess = false;
|
bool syncSuccess = false;
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
_safeRun(backgroundManager.syncLocal(full: CurrentPlatform.isAndroid ? true : false), "syncLocal"),
|
_safeRun(() => backgroundManager.syncLocal(full: CurrentPlatform.isAndroid), "syncLocal"),
|
||||||
_safeRun(backgroundManager.syncRemote().then((success) => syncSuccess = success), "syncRemote"),
|
_safeRun(() async {
|
||||||
|
syncSuccess = await backgroundManager.syncRemote();
|
||||||
|
}, "syncRemote"),
|
||||||
]);
|
]);
|
||||||
_ref.invalidate(driftMemoryFutureProvider);
|
_ref.invalidate(driftMemoryFutureProvider);
|
||||||
if (syncSuccess) {
|
if (syncSuccess) {
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
_safeRun(backgroundManager.hashAssets(), "hashAssets").then((_) {
|
_safeRun(backgroundManager.hashAssets, "hashAssets").then((_) {
|
||||||
unawaited(_resumeBackup());
|
unawaited(_resumeBackup());
|
||||||
}),
|
}),
|
||||||
_resumeBackup(),
|
_resumeBackup(),
|
||||||
|
|
@ -131,11 +133,11 @@ class AppLifeCycleNotifier extends StateNotifier<AppLifeCycleEnum> {
|
||||||
// _safeRun(backgroundManager.syncCloudIds(), "syncCloudIds"),
|
// _safeRun(backgroundManager.syncCloudIds(), "syncCloudIds"),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
await _safeRun(backgroundManager.hashAssets(), "hashAssets");
|
await _safeRun(backgroundManager.hashAssets, "hashAssets");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAlbumLinkedSyncEnable) {
|
if (isAlbumLinkedSyncEnable) {
|
||||||
await _safeRun(backgroundManager.syncLinkedAlbum(), "syncLinkedAlbum");
|
await _safeRun(backgroundManager.syncLinkedAlbum, "syncLinkedAlbum");
|
||||||
}
|
}
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
_log.severe("Error during background sync", e, stackTrace);
|
_log.severe("Error during background sync", e, stackTrace);
|
||||||
|
|
@ -149,7 +151,7 @@ class AppLifeCycleNotifier extends StateNotifier<AppLifeCycleEnum> {
|
||||||
final currentUser = Store.tryGet(StoreKey.currentUser);
|
final currentUser = Store.tryGet(StoreKey.currentUser);
|
||||||
if (currentUser != null) {
|
if (currentUser != null) {
|
||||||
await _safeRun(
|
await _safeRun(
|
||||||
_ref.read(driftBackupProvider.notifier).startForegroundBackup(currentUser.id),
|
() => _ref.read(driftBackupProvider.notifier).startForegroundBackup(currentUser.id),
|
||||||
"handleBackupResume",
|
"handleBackupResume",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue