Revert "refactor: Only initialize FlutterLocalNotificationsPlugin once"
This reverts commit d3a13705bd.
This commit is contained in:
parent
d3a13705bd
commit
a928ecec1e
2 changed files with 296 additions and 309 deletions
|
|
@ -71,7 +71,7 @@ class BackgroundPush {
|
||||||
|
|
||||||
BackgroundPush._(this.client) {
|
BackgroundPush._(this.client) {
|
||||||
firebase?.setListeners(
|
firebase?.setListeners(
|
||||||
onMessage: (message) => PushHelper.processNotification(
|
onMessage: (message) => pushHelper(
|
||||||
PushNotification.fromJson(
|
PushNotification.fromJson(
|
||||||
Map<String, dynamic>.from(message['data'] ?? message),
|
Map<String, dynamic>.from(message['data'] ?? message),
|
||||||
),
|
),
|
||||||
|
|
@ -393,7 +393,7 @@ class BackgroundPush {
|
||||||
);
|
);
|
||||||
// UP may strip the devices list
|
// UP may strip the devices list
|
||||||
data['devices'] ??= [];
|
data['devices'] ??= [];
|
||||||
await PushHelper.processNotification(
|
await pushHelper(
|
||||||
PushNotification.fromJson(data),
|
PushNotification.fromJson(data),
|
||||||
client: client,
|
client: client,
|
||||||
l10n: l10n,
|
l10n: l10n,
|
||||||
|
|
|
||||||
|
|
@ -18,31 +18,7 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:fluffychat/utils/voip/callkeep_manager.dart';
|
import 'package:fluffychat/utils/voip/callkeep_manager.dart';
|
||||||
|
|
||||||
abstract class PushHelper {
|
Future<void> pushHelper(
|
||||||
static FlutterLocalNotificationsPlugin? _flutterLocalNotificationsPlugin;
|
|
||||||
|
|
||||||
static Future<FlutterLocalNotificationsPlugin> _getLocalNotificationsPlugin({
|
|
||||||
void Function(NotificationResponse?)? onSelectNotification,
|
|
||||||
}) async {
|
|
||||||
var flutterlocalNotifcationsPlugin = _flutterLocalNotificationsPlugin;
|
|
||||||
if (flutterlocalNotifcationsPlugin != null) {
|
|
||||||
return flutterlocalNotifcationsPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
flutterlocalNotifcationsPlugin =
|
|
||||||
_flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
|
||||||
await flutterlocalNotifcationsPlugin.initialize(
|
|
||||||
const InitializationSettings(
|
|
||||||
android: AndroidInitializationSettings('notifications_icon'),
|
|
||||||
iOS: DarwinInitializationSettings(),
|
|
||||||
),
|
|
||||||
onDidReceiveNotificationResponse: onSelectNotification,
|
|
||||||
onDidReceiveBackgroundNotificationResponse: onSelectNotification,
|
|
||||||
);
|
|
||||||
return flutterlocalNotifcationsPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> processNotification(
|
|
||||||
PushNotification notification, {
|
PushNotification notification, {
|
||||||
Client? client,
|
Client? client,
|
||||||
L10n? l10n,
|
L10n? l10n,
|
||||||
|
|
@ -60,9 +36,15 @@ abstract class PushHelper {
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().v('Push Helper has crashed!', e, s);
|
Logs().v('Push Helper has crashed!', e, s);
|
||||||
|
|
||||||
final flutterLocalNotificationsPlugin =
|
// Initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
|
||||||
await _getLocalNotificationsPlugin(
|
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||||
onSelectNotification: onSelectNotification,
|
await flutterLocalNotificationsPlugin.initialize(
|
||||||
|
const InitializationSettings(
|
||||||
|
android: AndroidInitializationSettings('notifications_icon'),
|
||||||
|
iOS: DarwinInitializationSettings(),
|
||||||
|
),
|
||||||
|
onDidReceiveNotificationResponse: onSelectNotification,
|
||||||
|
onDidReceiveBackgroundNotificationResponse: onSelectNotification,
|
||||||
);
|
);
|
||||||
|
|
||||||
l10n ??= lookupL10n(const Locale('en'));
|
l10n ??= lookupL10n(const Locale('en'));
|
||||||
|
|
@ -90,7 +72,7 @@ abstract class PushHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> _tryPushHelper(
|
Future<void> _tryPushHelper(
|
||||||
PushNotification notification, {
|
PushNotification notification, {
|
||||||
Client? client,
|
Client? client,
|
||||||
L10n? l10n,
|
L10n? l10n,
|
||||||
|
|
@ -110,8 +92,15 @@ abstract class PushHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final flutterLocalNotificationsPlugin = await _getLocalNotificationsPlugin(
|
// Initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
|
||||||
onSelectNotification: onSelectNotification,
|
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||||
|
await flutterLocalNotificationsPlugin.initialize(
|
||||||
|
const InitializationSettings(
|
||||||
|
android: AndroidInitializationSettings('notifications_icon'),
|
||||||
|
iOS: DarwinInitializationSettings(),
|
||||||
|
),
|
||||||
|
onDidReceiveNotificationResponse: onSelectNotification,
|
||||||
|
//onDidReceiveBackgroundNotificationResponse: onSelectNotification,
|
||||||
);
|
);
|
||||||
|
|
||||||
client ??= (await ClientManager.getClients(
|
client ??= (await ClientManager.getClients(
|
||||||
|
|
@ -160,8 +149,7 @@ abstract class PushHelper {
|
||||||
client.backgroundSync = false;
|
client.backgroundSync = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type.startsWith('m.call') &&
|
if (event.type.startsWith('m.call') && event.type != EventTypes.CallInvite) {
|
||||||
event.type != EventTypes.CallInvite) {
|
|
||||||
Logs().v('Push message is a m.call but not invite. Do not display.');
|
Logs().v('Push message is a m.call but not invite. Do not display.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -329,7 +317,7 @@ abstract class PushHelper {
|
||||||
/// Creates a shortcut for Android platform but does not block displaying the
|
/// Creates a shortcut for Android platform but does not block displaying the
|
||||||
/// notification. This is optional but provides a nicer view of the
|
/// notification. This is optional but provides a nicer view of the
|
||||||
/// notification popup.
|
/// notification popup.
|
||||||
static Future<void> _setShortcut(
|
Future<void> _setShortcut(
|
||||||
Event event,
|
Event event,
|
||||||
L10n l10n,
|
L10n l10n,
|
||||||
String title,
|
String title,
|
||||||
|
|
@ -354,4 +342,3 @@ abstract class PushHelper {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue