π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix handling of notification in bg
Neeraj Gupta8c23a1db0a46
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dartindex ec2c86f426..76066ba137 100644--- a/mobile/apps/photos/lib/main.dart+++ b/mobile/apps/photos/lib/main.dart@@ -197,6 +197,7 @@ Future<void> _runMinimally(String taskId, TimeLogger tlog) async {// Misc Servicesawait UserService.instance.init();NotificationService.instance.init(prefs);+ await NotificationService.instance.initializeForBackground();// Begin Execution// only runs for android@@ -247,6 +248,7 @@ Future<void> _init(bool isBackground, {String via = ''}) async {_logger.info("_logFGHeartBeatInfo done $tlog");unawaited(_scheduleHeartBeat(preferences, isBackground));NotificationService.instance.init(preferences);+ await NotificationService.instance.initializeForBackground();AppLifecycleService.instance.init(preferences);if (isBackground) {AppLifecycleService.instance.onAppInBackground('init via: $via $tlog');diff --git a/mobile/apps/photos/lib/services/notification_service.dart b/mobile/apps/photos/lib/services/notification_service.dartindex 79decc0475..2bc4193d37 100644--- a/mobile/apps/photos/lib/services/notification_service.dart+++ b/mobile/apps/photos/lib/services/notification_service.dart@@ -23,6 +23,9 @@ class NotificationService {final FlutterLocalNotificationsPlugin _notificationsPlugin =FlutterLocalNotificationsPlugin();final _logger = Logger("NotificationService");+ void Function(NotificationResponse notificationResponse)? _onNotificationTapped;+ bool _pluginInitialized = false;+ bool _launchDetailsHandled = false;void init(SharedPreferences preferences) {_preferences = preferences;@@ -35,6 +38,21 @@ class NotificationService {NotificationResponse notificationResponse,) onNotificationTapped,) async {+ _onNotificationTapped = onNotificationTapped;+ await _ensurePluginInitialized();+ await _handleLaunchDetailsIfNeeded();+ if (!hasGrantedPermissions() &&+ RemoteSyncService.instance.isFirstRemoteSyncDone()) {+ await requestPermissions();+ }+ }++ Future<void> initializeForBackground() async {+ await _ensurePluginInitialized();+ }++ Future<void> _ensurePluginInitialized() async {+ if (_pluginInitialized) return;await initTimezones();const androidSettings = AndroidInitializationSettings('notification_icon');const iosSettings = DarwinInitializationSettings(@@ -50,20 +68,31 @@ class NotificationService {);await _notificationsPlugin.initialize(initializationSettings,- onDidReceiveNotificationResponse: onNotificationTapped,+ onDidReceiveNotificationResponse: _handleNotificationResponse,+ );+ _pluginInitialized = true;+ }++ void _handleNotificationResponse(NotificationResponse response) {+ if (_onNotificationTapped != null) {+ _onNotificationTapped!(response);+ return;+ }+ _logger.warning(+ "Notification response received before handler was set; ignoring.",);+ }+ Future<void> _handleLaunchDetailsIfNeeded() async {+ if (_launchDetailsHandled) return;final launchDetails =await _notificationsPlugin.getNotificationAppLaunchDetails();if (launchDetails != null &&launchDetails.didNotificationLaunchApp &&launchDetails.notificationResponse != null) {- onNotificationTapped(launchDetails.notificationResponse!);- }- if (!hasGrantedPermissions() &&- RemoteSyncService.instance.isFirstRemoteSyncDone()) {- await requestPermissions();+ _onNotificationTapped?.call(launchDetails.notificationResponse!);}+ _launchDetailsHandled = true;}Future<void> initTimezones() async {@@ -173,6 +202,7 @@ class NotificationService {channelDescription: 'ente alerts',importance: Importance.max,priority: Priority.high,+ icon: 'notification_icon',showWhen: false,);final iosSpecs = DarwinNotificationDetails(threadIdentifier: channelID);@@ -224,6 +254,7 @@ class NotificationService {importance: Importance.max,priority: Priority.high,category: AndroidNotificationCategory.reminder,+ icon: 'notification_icon',showWhen: false,timeoutAfter: timeoutDurationAndroid?.inMilliseconds,);diff --git a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart b/mobile/apps/photos/lib/services/sync/remote_sync_service.dartindex 55d640bd8a..31b5e81019 100644--- a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart+++ b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart@@ -1062,9 +1062,6 @@ class RemoteSyncService {/// Syncs social data and triggers notifications if needed.Future<void> _socialSync() async {- if (isProcessBg) {- return;- }try {_logger.info("Starting social sync");await SocialSyncService.instance.syncAllSharedCollections();@@ -1200,7 +1197,7 @@ class RemoteSyncService {title,message,channelID: "social_activity",- channelName: "Activity",+ channelName: "EnteFeed",payload: "ente://feed",);await _prefs.setInt(