chore: Follow up notification action isolate handling
This commit is contained in:
parent
b7e112a224
commit
3c049211ca
3 changed files with 27 additions and 3 deletions
|
|
@ -56,4 +56,7 @@ abstract class AppConfig {
|
|||
host: 'fluffy.chat',
|
||||
path: '/en/privacy',
|
||||
);
|
||||
|
||||
static const String mainIsolatePortName = 'main_isolate';
|
||||
static const String pushIsolatePortName = 'push_isolate';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import 'dart:isolate';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/utils/notification_background_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
|
|
@ -20,11 +22,12 @@ ReceivePort? mainIsolateReceivePort;
|
|||
void main() async {
|
||||
if (PlatformInfos.isAndroid) {
|
||||
final port = mainIsolateReceivePort = ReceivePort();
|
||||
IsolateNameServer.removePortNameMapping('main_isolate');
|
||||
IsolateNameServer.removePortNameMapping(AppConfig.mainIsolatePortName);
|
||||
IsolateNameServer.registerPortWithName(
|
||||
port.sendPort,
|
||||
'main_isolate',
|
||||
AppConfig.mainIsolatePortName,
|
||||
);
|
||||
await waitForPushIsolateDone();
|
||||
}
|
||||
|
||||
// Our background push shared isolate accesses flutter-internal things very early in the startup proccess
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:isolate';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
|
|
@ -42,11 +43,20 @@ extension NotificationResponseJson on NotificationResponse {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> waitForPushIsolateDone() async {
|
||||
if (IsolateNameServer.lookupPortByName(AppConfig.pushIsolatePortName) !=
|
||||
null) {
|
||||
Logs().i('Wait for Push Isolate to be done...');
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
}
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void notificationTapBackground(
|
||||
NotificationResponse notificationResponse,
|
||||
) async {
|
||||
final sendPort = IsolateNameServer.lookupPortByName('main_isolate');
|
||||
final sendPort =
|
||||
IsolateNameServer.lookupPortByName(AppConfig.mainIsolatePortName);
|
||||
if (sendPort != null) {
|
||||
sendPort.send(notificationResponse.toJsonString());
|
||||
Logs().i('Notification tap sent to main isolate!');
|
||||
|
|
@ -56,6 +66,12 @@ void notificationTapBackground(
|
|||
'Main isolate no up - Create temporary client for notification tap intend!',
|
||||
);
|
||||
|
||||
final pushIsolateReceivePort = ReceivePort();
|
||||
IsolateNameServer.registerPortWithName(
|
||||
pushIsolateReceivePort.sendPort,
|
||||
AppConfig.pushIsolatePortName,
|
||||
);
|
||||
|
||||
if (!_vodInitialized) {
|
||||
await vod.init();
|
||||
_vodInitialized = true;
|
||||
|
|
@ -79,6 +95,8 @@ void notificationTapBackground(
|
|||
await notificationTap(notificationResponse, client: client);
|
||||
} finally {
|
||||
await client.dispose(closeDatabase: false);
|
||||
pushIsolateReceivePort.sendPort.send('DONE');
|
||||
IsolateNameServer.removePortNameMapping(AppConfig.pushIsolatePortName);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue