From 10ef89ed3a9cc84660c2f57420d4e15a07c7efa7 Mon Sep 17 00:00:00 2001 From: Kris Hu Date: Sat, 12 Jul 2025 16:22:58 +0800 Subject: [PATCH] close push notifications when all have been read --- src/sw.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sw.ts b/src/sw.ts index 3c6ffaac..15a55479 100644 --- a/src/sw.ts +++ b/src/sw.ts @@ -141,6 +141,13 @@ const handlePushNotificationEventData = async (eventData: PushMessageData) => { } catch (e) { // Likely Firefox/Gecko-based and doesn't support badging API } + if (pushData.unread == 0) { + self.registration.getNotifications({ tag: "Cinny" }) + .then((notifications) => notifications + .forEach((notification) => notification.close())); + await navigator.clearAppBadge(); + return; + } } else { await navigator.clearAppBadge(); }