π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Re-arm the iOS processing task only from the foreground
laurenspriem4a1dfafcd8b3
diff --git a/mobile/apps/photos/lib/app.dart b/mobile/apps/photos/lib/app.dartindex 212b013fdc..e35d4ab556 100644--- a/mobile/apps/photos/lib/app.dart+++ b/mobile/apps/photos/lib/app.dart@@ -265,6 +265,7 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {unawaited(_reloadCachesUpdatedInBackground(lastAppOpenTime));SyncService.instance.sync();if (Platform.isIOS) {+ unawaited(BgTaskUtils.ensureIOSProcessingTaskScheduled());MLService.instance.triggerML();}} else {diff --git a/mobile/apps/photos/lib/utils/bg_task_utils.dart b/mobile/apps/photos/lib/utils/bg_task_utils.dartindex f083cd1a0a..9f5191ecf3 100644--- a/mobile/apps/photos/lib/utils/bg_task_utils.dart+++ b/mobile/apps/photos/lib/utils/bg_task_utils.dart@@ -2,6 +2,7 @@ import "dart:io";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/foundation.dart";+import "package:flutter/widgets.dart" show AppLifecycleState, WidgetsBinding;import "package:logging/logging.dart";import "package:permission_handler/permission_handler.dart";import "package:photos/db/upload_locks_db.dart";@@ -158,7 +159,11 @@ class BgTaskUtils {if (Platform.isIOS) {await reportUncleanProcessingTaskExit();// Background refresh permission does not reliably gate processing tasks.- await scheduleIOSBackgroundProcessingTask();+ final isForegroundLaunch =+ WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed;+ if (isForegroundLaunch) {+ await ensureIOSProcessingTaskScheduled();+ }final status = await Permission.backgroundRefresh.status;if (status != PermissionStatus.granted) {$.warning(@@ -204,8 +209,18 @@ class BgTaskUtils {}}+ static bool _processingTaskArmedThisProcess = false;++ // Foreground arm to restart the chain after a first install or force-quit;+ // once per process, so resumes don't keep pushing the pending request out.+ static Future<void> ensureIOSProcessingTaskScheduled() async {+ if (_processingTaskArmedThisProcess) return;+ _processingTaskArmedThisProcess =+ await scheduleIOSBackgroundProcessingTask();+ }+// Workmanager does not resubmit one-shot processing tasks.- static Future<void> scheduleIOSBackgroundProcessingTask() async {+ static Future<bool> scheduleIOSBackgroundProcessingTask() async {try {await workmanager.Workmanager().registerProcessingTask(iOSBackgroundProcessingTask,@@ -217,8 +232,10 @@ class BgTaskUtils {),);$.info("Scheduled iOS background processing task");+ return true;} catch (e) {$.warning("Failed to schedule iOS background processing task: $e");+ return false;}}}