feat: Desktop notifications on Linux Desktop

This commit is contained in:
Christian Pauly 2021-05-01 11:52:47 +02:00
parent 46f84b55de
commit 25e76f048e
3 changed files with 25 additions and 19 deletions

View File

@ -19,10 +19,7 @@ import 'package:provider/provider.dart';
import 'package:universal_html/html.dart' as html;
import 'package:http/http.dart' as http;
import 'package:url_launcher/url_launcher.dart';
/*import 'package:fluffychat/views/chat_ui.dart';
import 'package:fluffychat/app_config.dart';
import 'package:dbus/dbus.dart';
import 'package:desktop_notifications/desktop_notifications.dart';*/
import 'package:desktop_notifications/desktop_notifications.dart';
import '../../utils/beautify_string_extension.dart';
import '../../utils/localized_exception_extension.dart';
@ -184,6 +181,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
final room = client.getRoomById(roomId);
if (room.notificationCount == 0) return;
final event = Event.fromJson(eventUpdate.content, room);
final title = room.getLocalizedDisplayname(MatrixLocals(L10n.of(context)));
final body = event.getLocalizedBody(
MatrixLocals(L10n.of(context)),
withSenderNamePrefix:
@ -199,30 +197,22 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
..autoplay = true
..load();
html.Notification(
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
title,
body: body,
icon: icon.toString(),
);
} else if (Platform.isLinux) {
/*var sessionBus = DBusClient.session();
var client = NotificationClient(sessionBus);
_linuxNotificationIds[roomId] = await client.notify(
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
await linuxNotifications.notify(
title,
body: body,
replacesID: _linuxNotificationIds[roomId] ?? -1,
replacesId: _linuxNotificationIds[roomId] ?? -1,
appName: AppConfig.applicationName,
actionCallback: (_) => Navigator.of(context, rootNavigator: false).pushAndRemoveUntil(
AppRoute.defaultRoute(
context,
ChatView(roomId),
),
(r) => r.isFirst),
);
await sessionBus.close();*/
}
}
//final Map<String, int> _linuxNotificationIds = {};
final linuxNotifications = NotificationsClient();
final Map<String, int> _linuxNotificationIds = {};
@override
void initState() {
@ -416,6 +406,8 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
onBlurSub?.cancel();
_backgroundPush?.onLogin?.cancel();
linuxNotifications.close();
super.dispose();
}

View File

@ -183,6 +183,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
dbus:
dependency: transitive
description:
name: dbus
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
desktop_notifications:
dependency: "direct main"
description:
name: desktop_notifications
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
disk_space_ns:
dependency: transitive
description:

View File

@ -14,7 +14,7 @@ dependencies:
audioplayers: ^0.18.3
cached_network_image: ^3.0.0
cupertino_icons: any
# desktop_notifications: ^0.0.0-dev.4 // Currently blocked by: https://github.com/canonical/desktop_notifications.dart/issues/5
desktop_notifications: ^0.4.0
email_validator: ^2.0.1
emoji_picker_flutter: ^1.0.3
famedlysdk: