From 11627e2455d4127cac5bb8d4a277ef3788044b63 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 6 Feb 2025 14:48:41 +0800 Subject: [PATCH] :lipstick: Clear tray number when click from it --- lib/main.dart | 2 ++ lib/providers/notification.dart | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/main.dart b/lib/main.dart index 92e9c30..6a35709 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -369,6 +369,7 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { @override void onTrayIconMouseDown() { if (Platform.isWindows) { + context.read().clearTray(); appWindow.show(); } else { trayManager.popUpContextMenu(); @@ -380,6 +381,7 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { if (Platform.isWindows) { trayManager.popUpContextMenu(); } else { + context.read().clearTray(); appWindow.show(); } } diff --git a/lib/providers/notification.dart b/lib/providers/notification.dart index 431900b..1e53080 100644 --- a/lib/providers/notification.dart +++ b/lib/providers/notification.dart @@ -73,6 +73,7 @@ class NotificationProvider extends ChangeNotifier { } int showingCount = 0; + int showingTrayCount = 0; List notifications = List.empty(growable: true); void listen() { @@ -81,6 +82,7 @@ class NotificationProvider extends ChangeNotifier { final notification = SnNotification.fromJson(event.payload!); if (showingCount < 0) showingCount = 0; showingCount++; + showingTrayCount++; notifications.add(notification); Future.delayed(const Duration(seconds: 3), () { if (showingCount >= 0) showingCount--; @@ -94,6 +96,11 @@ class NotificationProvider extends ChangeNotifier { }); } + void clearTray() { + showingTrayCount = 0; + updateTray(); + } + void updateTray() { if (kIsWeb || Platform.isAndroid || Platform.isIOS) return; if (notifications.isEmpty) {