High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix(mobile): don't start the foreground backup in iOS background launches (#31943)
Santo Shakil3e4492924541
diff --git a/mobile/lib/pages/common/splash_screen.page.dart b/mobile/lib/pages/common/splash_screen.page.dartindex ab803b669a..385dcdce26 100644--- a/mobile/lib/pages/common/splash_screen.page.dart+++ b/mobile/lib/pages/common/splash_screen.page.dart@@ -10,9 +10,11 @@ import 'package:immich_mobile/data/db/main/database.dart';import 'package:immich_mobile/domain/models/config/app_config.dart';import 'package:immich_mobile/domain/models/store.model.dart';import 'package:immich_mobile/entities/store.entity.dart';+import 'package:immich_mobile/extensions/platform_extensions.dart';import 'package:immich_mobile/generated/codegen_loader.g.dart';import 'package:immich_mobile/generated/translations.g.dart';import 'package:immich_mobile/infrastructure/repositories/settings.repository.dart';+import 'package:immich_mobile/providers/app_life_cycle.provider.dart';import 'package:immich_mobile/providers/auth.provider.dart';import 'package:immich_mobile/providers/background_sync.provider.dart';import 'package:immich_mobile/providers/backup/backup.provider.dart';@@ -311,6 +313,7 @@ class SplashScreenPageState extends ConsumerState<SplashScreenPage> {final wsProvider = ref.read(websocketProvider.notifier);final backgroundManager = ref.read(backgroundSyncProvider);final backupNotifier = ref.read(backupProvider.notifier);+ final lifeCycle = ref.read(appStateProvider.notifier);final viewIntentHandler = ref.read(viewIntentHandlerProvider);unawaited(@@ -334,9 +337,9 @@ class SplashScreenPageState extends ConsumerState<SplashScreenPage> {if (syncSuccess) {await Future.wait([backgroundManager.hashAssets().then((_) {- unawaited(_resumeBackup(backupNotifier));+ unawaited(_resumeBackup(backupNotifier, lifeCycle));}),- _resumeBackup(backupNotifier),+ _resumeBackup(backupNotifier, lifeCycle),backgroundManager.syncCloudIds(),]);} else {@@ -375,12 +378,19 @@ class SplashScreenPageState extends ConsumerState<SplashScreenPage> {}}- Future<void> _resumeBackup(BackupNotifier notifier) async {+ Future<void> _resumeBackup(BackupNotifier notifier, AppLifeCycleNotifier lifeCycle) async {final isEnableBackup = SettingsRepository.instance.appConfig.backup.enabled;if (isEnableBackup) {final currentUser = Store.tryGet(StoreKey.currentUser);if (currentUser != null) {+ // TODO(rewrite): Remove this check and requestFullResume once the splash no longer runs in background launches+ // iOS also runs the splash in background launches, where the app is never resumed.+ // there the foreground backup waits for the first resume instead of uploading off screen+ if (CurrentPlatform.isIOS && WidgetsBinding.instance.lifecycleState != AppLifecycleState.resumed) {+ lifeCycle.requestFullResume();+ return;+ }unawaited(notifier.startForegroundBackup(currentUser.id));}}diff --git a/mobile/lib/providers/app_life_cycle.provider.dart b/mobile/lib/providers/app_life_cycle.provider.dartindex 33c76fdd2d..4f4f20efd3 100644--- a/mobile/lib/providers/app_life_cycle.provider.dart+++ b/mobile/lib/providers/app_life_cycle.provider.dart@@ -33,6 +33,8 @@ class AppLifeCycleNotifier extends StateNotifier<AppLifeCycleEnum> {AppLifeCycleNotifier(this._ref) : super(AppLifeCycleEnum.active);+ void requestFullResume() => _fullSyncPending = true;+Future<void> handleAppResume() async {state = AppLifeCycleEnum.resumed;_log.info("App resumed");@@ -65,7 +67,8 @@ class AppLifeCycleNotifier extends StateNotifier<AppLifeCycleEnum> {Future<void> _performResume() async {if (_firstLaunch) {// a delta sync can miss photos taken after a background launch- _fullSyncPending = await _ref.read(backgroundWorkerFgServiceProvider).wasLaunchedInBackground();+ _fullSyncPending =+ await _ref.read(backgroundWorkerFgServiceProvider).wasLaunchedInBackground() || _fullSyncPending;_firstLaunch = false;}diff --git a/mobile/test/providers/app_life_cycle_provider_test.dart b/mobile/test/providers/app_life_cycle_provider_test.dartindex da6f7cf5c6..abc7721a1d 100644--- a/mobile/test/providers/app_life_cycle_provider_test.dart+++ b/mobile/test/providers/app_life_cycle_provider_test.dart@@ -258,6 +258,17 @@ void main() {verify(() => backgroundSync.syncLocal(full: false)).called(1);});+ test('first resume runs when the splash requested a full resume', () async {+ websocket.throwOnConnect = false;+ serverVersion.complete();+ lifeCycle.requestFullResume();+ await lifeCycle.handleAppResume();++ expect(serverVersionCount, 1);+ expect(websocket.connectCount, 1);+ verify(() => backgroundSync.syncLocal(full: true)).called(1);+ });+test('a background launch does not resume twice without a pause', () async {when(() => fgService.wasLaunchedInBackground()).thenAnswer((_) async => true);websocket.throwOnConnect = false;