Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String, dynamic>;

Expand Down Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions commet/lib/ui/atoms/room_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -298,18 +299,9 @@ class _HeaderBurgerState extends State<HeaderBurger> {
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;
Expand Down
23 changes: 23 additions & 0 deletions commet/lib/utils/notification_utils.dart
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions commet/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading