From 5e7272b15a5979f99a5ab47e769cdc4bd2979df8 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Wed, 23 Feb 2022 11:13:03 -0800 Subject: [PATCH] nix notification manager only use title, body is unsafe --- lib/notification_manager.dart | 34 ++++++++++++++++++---------------- pubspec.lock | 13 +++---------- pubspec.yaml | 1 - 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/lib/notification_manager.dart b/lib/notification_manager.dart index 82e23817..1bbd2519 100644 --- a/lib/notification_manager.dart +++ b/lib/notification_manager.dart @@ -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 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()?.requestPermissions( alert: true, - badge: true, - sound: true, + badge: false, + sound: false, ); scheduleMicrotask(() async { @@ -99,16 +98,19 @@ class NixNotificationManager implements NotificationsManager { }); } + Future 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 payloadMap = jsonDecode(payloadJson); - var payload = NotificationPayload.fromJson(payloadMap); + var payload = NotificationPayload.fromJson(payloadMap); notificationSelectConvo(payload.profileOnion, payload.convoId); } -} - - Future notify(String message, String profile, int conversationId) async { - await flutterLocalNotificationsPlugin.show(0, 'Cwtch', message, null, payload: jsonEncode(NotificationPayload(profile, conversationId))); } } diff --git a/pubspec.lock b/pubspec.lock index 2a4d1f66..422ef085 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index f5d90737..a171f87f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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