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',
|
host: 'fluffy.chat',
|
||||||
path: '/en/privacy',
|
path: '/en/privacy',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
static const String mainIsolatePortName = 'main_isolate';
|
||||||
|
static const String pushIsolatePortName = 'push_isolate';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import 'dart:isolate';
|
import 'dart:isolate';
|
||||||
import 'dart:ui';
|
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:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
|
@ -20,11 +22,12 @@ ReceivePort? mainIsolateReceivePort;
|
||||||
void main() async {
|
void main() async {
|
||||||
if (PlatformInfos.isAndroid) {
|
if (PlatformInfos.isAndroid) {
|
||||||
final port = mainIsolateReceivePort = ReceivePort();
|
final port = mainIsolateReceivePort = ReceivePort();
|
||||||
IsolateNameServer.removePortNameMapping('main_isolate');
|
IsolateNameServer.removePortNameMapping(AppConfig.mainIsolatePortName);
|
||||||
IsolateNameServer.registerPortWithName(
|
IsolateNameServer.registerPortWithName(
|
||||||
port.sendPort,
|
port.sendPort,
|
||||||
'main_isolate',
|
AppConfig.mainIsolatePortName,
|
||||||
);
|
);
|
||||||
|
await waitForPushIsolateDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our background push shared isolate accesses flutter-internal things very early in the startup proccess
|
// Our background push shared isolate accesses flutter-internal things very early in the startup proccess
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:isolate';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
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')
|
@pragma('vm:entry-point')
|
||||||
void notificationTapBackground(
|
void notificationTapBackground(
|
||||||
NotificationResponse notificationResponse,
|
NotificationResponse notificationResponse,
|
||||||
) async {
|
) async {
|
||||||
final sendPort = IsolateNameServer.lookupPortByName('main_isolate');
|
final sendPort =
|
||||||
|
IsolateNameServer.lookupPortByName(AppConfig.mainIsolatePortName);
|
||||||
if (sendPort != null) {
|
if (sendPort != null) {
|
||||||
sendPort.send(notificationResponse.toJsonString());
|
sendPort.send(notificationResponse.toJsonString());
|
||||||
Logs().i('Notification tap sent to main isolate!');
|
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!',
|
'Main isolate no up - Create temporary client for notification tap intend!',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final pushIsolateReceivePort = ReceivePort();
|
||||||
|
IsolateNameServer.registerPortWithName(
|
||||||
|
pushIsolateReceivePort.sendPort,
|
||||||
|
AppConfig.pushIsolatePortName,
|
||||||
|
);
|
||||||
|
|
||||||
if (!_vodInitialized) {
|
if (!_vodInitialized) {
|
||||||
await vod.init();
|
await vod.init();
|
||||||
_vodInitialized = true;
|
_vodInitialized = true;
|
||||||
|
|
@ -79,6 +95,8 @@ void notificationTapBackground(
|
||||||
await notificationTap(notificationResponse, client: client);
|
await notificationTap(notificationResponse, client: client);
|
||||||
} finally {
|
} finally {
|
||||||
await client.dispose(closeDatabase: false);
|
await client.dispose(closeDatabase: false);
|
||||||
|
pushIsolateReceivePort.sendPort.send('DONE');
|
||||||
|
IsolateNameServer.removePortNameMapping(AppConfig.pushIsolatePortName);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue