From b7e112a22464b2085639f3c170af6a681c7f8dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Wed, 12 Nov 2025 08:37:10 +0100 Subject: [PATCH] chore: Follow up notification actions --- lib/main.dart | 1 + lib/utils/background_push.dart | 15 +++++++++++++++ lib/utils/notification_background_handler.dart | 6 ++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 37e472add..00fe37474 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -20,6 +20,7 @@ ReceivePort? mainIsolateReceivePort; void main() async { if (PlatformInfos.isAndroid) { final port = mainIsolateReceivePort = ReceivePort(); + IsolateNameServer.removePortNameMapping('main_isolate'); IsolateNameServer.registerPortWithName( port.sendPort, 'main_isolate', diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index 31b1e82e2..533bedfac 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -34,6 +34,7 @@ import 'package:unifiedpush/unifiedpush.dart'; import 'package:unifiedpush_ui/unifiedpush_ui.dart'; import 'package:fluffychat/l10n/l10n.dart'; +import 'package:fluffychat/main.dart'; import 'package:fluffychat/utils/notification_background_handler.dart'; import 'package:fluffychat/utils/push_helper.dart'; import 'package:fluffychat/widgets/fluffy_chat_app.dart'; @@ -77,6 +78,20 @@ class BackgroundPush { void _init() async { //firebaseEnabled = true; try { + mainIsolateReceivePort?.listen( + (message) async { + try { + await notificationTap( + NotificationResponseJson.fromJsonString(message), + client: client, + router: FluffyChatApp.router, + l10n: l10n, + ); + } catch (e, s) { + Logs().wtf('Main Notification Tap crashed', e, s); + } + }, + ); if (PlatformInfos.isAndroid) { final port = ReceivePort(); IsolateNameServer.removePortNameMapping('background_tab_port'); diff --git a/lib/utils/notification_background_handler.dart b/lib/utils/notification_background_handler.dart index 32113502a..a0fcd4792 100644 --- a/lib/utils/notification_background_handler.dart +++ b/lib/utils/notification_background_handler.dart @@ -46,13 +46,15 @@ extension NotificationResponseJson on NotificationResponse { void notificationTapBackground( NotificationResponse notificationResponse, ) async { - Logs().i('Notification tap in background'); - final sendPort = IsolateNameServer.lookupPortByName('main_isolate'); if (sendPort != null) { sendPort.send(notificationResponse.toJsonString()); + Logs().i('Notification tap sent to main isolate!'); return; } + Logs().i( + 'Main isolate no up - Create temporary client for notification tap intend!', + ); if (!_vodInitialized) { await vod.init();