mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-27 14:59:29 +01:00
feat: Desktop notifications on Linux Desktop
This commit is contained in:
parent
46f84b55de
commit
25e76f048e
@ -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();
|
||||
}
|
||||
|
||||
|
14
pubspec.lock
14
pubspec.lock
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user