nix notification manager only use title, body is unsafe
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Dan Ballard 2022-02-23 11:13:03 -08:00
parent 1a4dccf44a
commit 5e7272b15a
3 changed files with 21 additions and 27 deletions

View File

@ -4,8 +4,11 @@ import 'dart:io';
import 'package:cwtch/main.dart';
import 'package:win_toast/win_toast.dart';
import 'package:desktop_notifications/desktop_notifications.dart';
//import 'package:desktop_notifications/desktop_notifications.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_local_notifications_linux/flutter_local_notifications_linux.dart';
import 'package:flutter_local_notifications_linux/src/model/hint.dart';
import 'package:path/path.dart' as path;
import 'config.dart';
@ -64,9 +67,9 @@ class NotificationPayload {
convoId = json['convoId'];
Map<String, dynamic> toJson() => {
'profileOnion': profileOnion,
'convoId': convoId,
};
'profileOnion': profileOnion,
'convoId': convoId,
};
}
// FlutterLocalNotificationsPlugin based NotificationManager that handles Linux and MacOS
@ -80,18 +83,14 @@ class NixNotificationManager implements NotificationsManager {
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
final MacOSInitializationSettings initializationSettingsMacOS = MacOSInitializationSettings(defaultPresentSound: true);
final LinuxInitializationSettings initializationSettingsLinux =
LinuxInitializationSettings(
defaultActionName: 'Open notification',
defaultIcon: AssetsLinuxIcon('assets/knott.png'),
defaultSuppressSound: true
);
LinuxInitializationSettings(defaultActionName: 'Open notification', defaultIcon: AssetsLinuxIcon('assets/knott.png'), defaultSuppressSound: true);
final InitializationSettings initializationSettings = InitializationSettings(android: null, iOS: null, macOS: initializationSettingsMacOS, linux: initializationSettingsLinux);
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<MacOSFlutterLocalNotificationsPlugin>()?.requestPermissions(
alert: true,
badge: true,
sound: true,
badge: false,
sound: false,
);
scheduleMicrotask(() async {
@ -99,16 +98,19 @@ class NixNotificationManager implements NotificationsManager {
});
}
Future<void> notify(String message, String profile, int conversationId) async {
// Warning: Only use title field on Linux, body field will render links as clickable
await flutterLocalNotificationsPlugin.show(0, message, '', NotificationDetails(linux: LinuxNotificationDetails(suppressSound: true, category: LinuxNotificationCategory.imReceived())),
payload: jsonEncode(NotificationPayload(profile, conversationId)));
}
// Notification click response function, triggers ui jump to conversation
void selectNotification(String? payloadJson) async {
if (payloadJson != null) {
Map<String, dynamic> payloadMap = jsonDecode(payloadJson);
var payload = NotificationPayload.fromJson(payloadMap);
var payload = NotificationPayload.fromJson(payloadMap);
notificationSelectConvo(payload.profileOnion, payload.convoId);
}
}
Future<void> notify(String message, String profile, int conversationId) async {
await flutterLocalNotificationsPlugin.show(0, 'Cwtch', message, null, payload: jsonEncode(NotificationPayload(profile, conversationId)));
}
}

View File

@ -189,14 +189,7 @@ packages:
name: dbus
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.8"
desktop_notifications:
dependency: "direct main"
description:
name: desktop_notifications
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.0"
version: "0.7.1"
fake_async:
dependency: transitive
description:
@ -269,7 +262,7 @@ packages:
name: flutter_local_notifications_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.1+1"
version: "0.4.2"
flutter_local_notifications_platform_interface:
dependency: transitive
description:
@ -824,7 +817,7 @@ packages:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
version: "0.2.0+1"
xml:
dependency: transitive
description:

View File

@ -42,7 +42,6 @@ dependencies:
file_picker_desktop: ^1.1.0
url_launcher: ^6.0.18
window_manager: ^0.1.4
desktop_notifications: 0.6.0
win_toast: ^0.0.2
flutter_local_notifications: 9.3.2