From 555fbde840e6541137ac5172425dd945cdc8bca5 Mon Sep 17 00:00:00 2001 From: shenlong <139912620+shenlong-tanwen@users.noreply.github.com> Date: Wed, 5 Aug 2026 21:22:31 +0530 Subject: [PATCH 1/2] fix: _safeRun is finally safe (#30571) Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> --- .../lib/providers/app_life_cycle.provider.dart | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mobile/lib/providers/app_life_cycle.provider.dart b/mobile/lib/providers/app_life_cycle.provider.dart index df17e37021..7dc475ab93 100644 --- a/mobile/lib/providers/app_life_cycle.provider.dart +++ b/mobile/lib/providers/app_life_cycle.provider.dart @@ -93,13 +93,13 @@ class AppLifeCycleNotifier extends StateNotifier { await _ref.read(galleryPermissionNotifier.notifier).getGalleryPermissionStatus(); } - Future _safeRun(Future action, String debugName) async { + Future _safeRun(Future Function() action, String debugName) async { if (!_shouldContinueOperation()) { return; } try { - await action; + await action(); } catch (e, stackTrace) { _log.warning("Error during $debugName operation", e, stackTrace); } @@ -117,13 +117,15 @@ class AppLifeCycleNotifier extends StateNotifier { try { bool syncSuccess = false; await Future.wait([ - _safeRun(backgroundManager.syncLocal(full: CurrentPlatform.isAndroid ? true : false), "syncLocal"), - _safeRun(backgroundManager.syncRemote().then((success) => syncSuccess = success), "syncRemote"), + _safeRun(() => backgroundManager.syncLocal(full: CurrentPlatform.isAndroid), "syncLocal"), + _safeRun(() async { + syncSuccess = await backgroundManager.syncRemote(); + }, "syncRemote"), ]); _ref.invalidate(driftMemoryFutureProvider); if (syncSuccess) { await Future.wait([ - _safeRun(backgroundManager.hashAssets(), "hashAssets").then((_) { + _safeRun(backgroundManager.hashAssets, "hashAssets").then((_) { unawaited(_resumeBackup()); }), _resumeBackup(), @@ -131,11 +133,11 @@ class AppLifeCycleNotifier extends StateNotifier { // _safeRun(backgroundManager.syncCloudIds(), "syncCloudIds"), ]); } else { - await _safeRun(backgroundManager.hashAssets(), "hashAssets"); + await _safeRun(backgroundManager.hashAssets, "hashAssets"); } if (isAlbumLinkedSyncEnable) { - await _safeRun(backgroundManager.syncLinkedAlbum(), "syncLinkedAlbum"); + await _safeRun(backgroundManager.syncLinkedAlbum, "syncLinkedAlbum"); } } catch (e, stackTrace) { _log.severe("Error during background sync", e, stackTrace); @@ -149,7 +151,7 @@ class AppLifeCycleNotifier extends StateNotifier { final currentUser = Store.tryGet(StoreKey.currentUser); if (currentUser != null) { await _safeRun( - _ref.read(driftBackupProvider.notifier).startForegroundBackup(currentUser.id), + () => _ref.read(driftBackupProvider.notifier).startForegroundBackup(currentUser.id), "handleBackupResume", ); } From db2033a4b0261cb4b64486148a2e5e73c2660bc7 Mon Sep 17 00:00:00 2001 From: shenlong <139912620+shenlong-tanwen@users.noreply.github.com> Date: Wed, 5 Aug 2026 22:15:50 +0530 Subject: [PATCH 2/2] chore: add reason for stopForegroundBackup in tests (#30573) Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> --- mobile/test/providers/backup/drift_backup_provider_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/test/providers/backup/drift_backup_provider_test.dart b/mobile/test/providers/backup/drift_backup_provider_test.dart index 9a5f222301..205f564cd9 100644 --- a/mobile/test/providers/backup/drift_backup_provider_test.dart +++ b/mobile/test/providers/backup/drift_backup_provider_test.dart @@ -76,7 +76,7 @@ void main() { firstRun('asset-1', 'remote-1'); expect(notifier.state.remainderCount, 0); - notifier.stopForegroundBackup(); + notifier.stopForegroundBackup(reason: "test"); final resumedRun = await startAndCaptureOnSuccess(); expect(notifier.state.remainderCount, 1);