From f74871e9edf1c98fb1976d122c34c3888b55a258 Mon Sep 17 00:00:00 2001 From: Airyzz <36567925+Airyzz@users.noreply.github.com> Date: Fri, 13 Mar 2026 19:06:09 +1030 Subject: [PATCH] show notification badge on linux --- .../linux/linux_notifier.dart | 17 ++++++++++++++ commet/lib/ui/atoms/room_header.dart | 16 ++++--------- commet/lib/utils/notification_utils.dart | 23 +++++++++++++++++++ commet/pubspec.yaml | 1 + pubspec.lock | 8 +++++++ 5 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 commet/lib/utils/notification_utils.dart diff --git a/commet/lib/client/components/push_notification/linux/linux_notifier.dart b/commet/lib/client/components/push_notification/linux/linux_notifier.dart index f15927a96..2beba9ec7 100644 --- a/commet/lib/client/components/push_notification/linux/linux_notifier.dart +++ b/commet/lib/client/components/push_notification/linux/linux_notifier.dart @@ -10,11 +10,13 @@ import 'package:commet/utils/common_strings.dart'; import 'package:commet/utils/event_bus.dart'; import 'package:commet/utils/image/lod_image.dart'; import 'package:commet/utils/image_utils.dart'; +import 'package:commet/utils/notification_utils.dart'; import 'package:commet/utils/shortcuts_manager.dart'; import 'package:desktop_notifications/desktop_notifications.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_local_notifications_linux/src/model/hint.dart' as notif; +import 'package:launcher_entry/launcher_entry.dart'; import 'package:window_manager/window_manager.dart'; import 'dart:ui' as ui; @@ -44,6 +46,9 @@ class LinuxNotifier implements Notifier { late LinuxServerCapabilities capabilities; + final service = LauncherEntryService( + appUri: 'application://chat.commet.commetapp.desktop'); + static void notificationResponse(NotificationResponse details) { final payload = jsonDecode(details.payload!) as Map; @@ -116,6 +121,18 @@ class LinuxNotifier implements Notifier { onDidReceiveNotificationResponse: notificationResponse); capabilities = await flutterLocalNotificationsPlugin!.getCapabilities(); + + clientManager!.directMessages.onHighlightedRoomsListUpdated + .listen((_) => updateBadgeCount()); + clientManager!.onSpaceUpdated.stream.listen((_) => updateBadgeCount()); + + updateBadgeCount(); + } + + void updateBadgeCount() { + var counts = NotificationUtils.getNotificationCounts(); + var count = counts.$2; + service.update(countVisible: count > 0, count: count); } @override diff --git a/commet/lib/ui/atoms/room_header.dart b/commet/lib/ui/atoms/room_header.dart index 7c5001bf7..036f28c61 100644 --- a/commet/lib/ui/atoms/room_header.dart +++ b/commet/lib/ui/atoms/room_header.dart @@ -5,6 +5,7 @@ import 'package:commet/client/components/user_presence/user_presence_component.d import 'package:commet/config/layout_config.dart'; import 'package:commet/main.dart'; // For preferences import 'package:commet/ui/molecules/user_panel.dart'; +import 'package:commet/utils/notification_utils.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart' as m; import 'package:flutter/widgets.dart'; @@ -298,18 +299,9 @@ class _HeaderBurgerState extends State { highlightedNotificationCount = 0; notificationCount = 0; - var topLevelSpaces = - clientManager!.spaces.where((e) => e.isTopLevel).toList(); - - for (var i in topLevelSpaces) { - highlightedNotificationCount += i.displayHighlightedNotificationCount; - notificationCount += i.displayNotificationCount; - } - - for (var dm in clientManager!.directMessages.highlightedRoomsList) { - highlightedNotificationCount += dm.displayNotificationCount; - notificationCount += dm.displayNotificationCount; - } + var counts = NotificationUtils.getNotificationCounts(); + highlightedNotificationCount = counts.$1; + notificationCount = counts.$2; if (notificationCount > 0) { color = widget.notificationColor; diff --git a/commet/lib/utils/notification_utils.dart b/commet/lib/utils/notification_utils.dart new file mode 100644 index 000000000..c4716dc86 --- /dev/null +++ b/commet/lib/utils/notification_utils.dart @@ -0,0 +1,23 @@ +import 'package:commet/main.dart'; + +class NotificationUtils { + static (int, int) getNotificationCounts() { + var highlightedNotificationCount = 0; + var notificationCount = 0; + + var topLevelSpaces = + clientManager!.spaces.where((e) => e.isTopLevel).toList(); + + for (var i in topLevelSpaces) { + highlightedNotificationCount += i.displayHighlightedNotificationCount; + notificationCount += i.displayNotificationCount; + } + + for (var dm in clientManager!.directMessages.highlightedRoomsList) { + highlightedNotificationCount += dm.displayNotificationCount; + notificationCount += dm.displayNotificationCount; + } + + return (highlightedNotificationCount, notificationCount); + } +} diff --git a/commet/pubspec.yaml b/commet/pubspec.yaml index 96c3b5ae5..bba9030ee 100644 --- a/commet/pubspec.yaml +++ b/commet/pubspec.yaml @@ -123,6 +123,7 @@ dependencies: dart_ipc: ^1.0.1 dbus: ^0.7.11 hotkey_manager: ^0.2.3 + launcher_entry: ^0.1.1 dependency_overrides: analyzer: ^7.3.0 diff --git a/pubspec.lock b/pubspec.lock index b9a6559bc..fea9afeb9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1099,6 +1099,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.0.12" + launcher_entry: + dependency: transitive + description: + name: launcher_entry + sha256: "87c403fce3f9beea51514a7c5859aac57c9af6b795433a29ee9caa7b5bba9ac1" + url: "https://pub.dev" + source: hosted + version: "0.1.1" leak_tracker: dependency: transitive description: