💄 Clear tray number when click from it

This commit is contained in:
LittleSheep 2025-02-06 14:48:41 +08:00
parent 3f82c06ff8
commit 11627e2455
2 changed files with 9 additions and 0 deletions

View File

@ -369,6 +369,7 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener {
@override @override
void onTrayIconMouseDown() { void onTrayIconMouseDown() {
if (Platform.isWindows) { if (Platform.isWindows) {
context.read<NotificationProvider>().clearTray();
appWindow.show(); appWindow.show();
} else { } else {
trayManager.popUpContextMenu(); trayManager.popUpContextMenu();
@ -380,6 +381,7 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener {
if (Platform.isWindows) { if (Platform.isWindows) {
trayManager.popUpContextMenu(); trayManager.popUpContextMenu();
} else { } else {
context.read<NotificationProvider>().clearTray();
appWindow.show(); appWindow.show();
} }
} }

View File

@ -73,6 +73,7 @@ class NotificationProvider extends ChangeNotifier {
} }
int showingCount = 0; int showingCount = 0;
int showingTrayCount = 0;
List<SnNotification> notifications = List.empty(growable: true); List<SnNotification> notifications = List.empty(growable: true);
void listen() { void listen() {
@ -81,6 +82,7 @@ class NotificationProvider extends ChangeNotifier {
final notification = SnNotification.fromJson(event.payload!); final notification = SnNotification.fromJson(event.payload!);
if (showingCount < 0) showingCount = 0; if (showingCount < 0) showingCount = 0;
showingCount++; showingCount++;
showingTrayCount++;
notifications.add(notification); notifications.add(notification);
Future.delayed(const Duration(seconds: 3), () { Future.delayed(const Duration(seconds: 3), () {
if (showingCount >= 0) showingCount--; if (showingCount >= 0) showingCount--;
@ -94,6 +96,11 @@ class NotificationProvider extends ChangeNotifier {
}); });
} }
void clearTray() {
showingTrayCount = 0;
updateTray();
}
void updateTray() { void updateTray() {
if (kIsWeb || Platform.isAndroid || Platform.isIOS) return; if (kIsWeb || Platform.isAndroid || Platform.isIOS) return;
if (notifications.isEmpty) { if (notifications.isEmpty) {