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:cwtch/main.dart';
import 'package:win_toast/win_toast.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/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 'package:path/path.dart' as path;
import 'config.dart'; import 'config.dart';
@ -64,9 +67,9 @@ class NotificationPayload {
convoId = json['convoId']; convoId = json['convoId'];
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
'profileOnion': profileOnion, 'profileOnion': profileOnion,
'convoId': convoId, 'convoId': convoId,
}; };
} }
// FlutterLocalNotificationsPlugin based NotificationManager that handles Linux and MacOS // FlutterLocalNotificationsPlugin based NotificationManager that handles Linux and MacOS
@ -80,18 +83,14 @@ class NixNotificationManager implements NotificationsManager {
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
final MacOSInitializationSettings initializationSettingsMacOS = MacOSInitializationSettings(defaultPresentSound: true); final MacOSInitializationSettings initializationSettingsMacOS = MacOSInitializationSettings(defaultPresentSound: true);
final LinuxInitializationSettings initializationSettingsLinux = final LinuxInitializationSettings initializationSettingsLinux =
LinuxInitializationSettings( LinuxInitializationSettings(defaultActionName: 'Open notification', defaultIcon: AssetsLinuxIcon('assets/knott.png'), defaultSuppressSound: true);
defaultActionName: 'Open notification',
defaultIcon: AssetsLinuxIcon('assets/knott.png'),
defaultSuppressSound: true
);
final InitializationSettings initializationSettings = InitializationSettings(android: null, iOS: null, macOS: initializationSettingsMacOS, linux: initializationSettingsLinux); final InitializationSettings initializationSettings = InitializationSettings(android: null, iOS: null, macOS: initializationSettingsMacOS, linux: initializationSettingsLinux);
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<MacOSFlutterLocalNotificationsPlugin>()?.requestPermissions( flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<MacOSFlutterLocalNotificationsPlugin>()?.requestPermissions(
alert: true, alert: true,
badge: true, badge: false,
sound: true, sound: false,
); );
scheduleMicrotask(() async { 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 { void selectNotification(String? payloadJson) async {
if (payloadJson != null) { if (payloadJson != null) {
Map<String, dynamic> payloadMap = jsonDecode(payloadJson); Map<String, dynamic> payloadMap = jsonDecode(payloadJson);
var payload = NotificationPayload.fromJson(payloadMap); var payload = NotificationPayload.fromJson(payloadMap);
notificationSelectConvo(payload.profileOnion, payload.convoId); 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 name: dbus
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.6.8" version: "0.7.1"
desktop_notifications:
dependency: "direct main"
description:
name: desktop_notifications
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.0"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
@ -269,7 +262,7 @@ packages:
name: flutter_local_notifications_linux name: flutter_local_notifications_linux
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.1+1" version: "0.4.2"
flutter_local_notifications_platform_interface: flutter_local_notifications_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -824,7 +817,7 @@ packages:
name: xdg_directories name: xdg_directories
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.0" version: "0.2.0+1"
xml: xml:
dependency: transitive dependency: transitive
description: description:

View File

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