aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-07-25 04:25:22 -0700
committerFuwn <[email protected]>2024-07-25 04:25:22 -0700
commit118eb7f2b25b3f9d6e9c25e02ccc15401286fd22 (patch)
tree9e7d1b0ae8da761fd2b96b962b5b7908636bbc3f
parentfix(service-worker): properly await all promises (diff)
downloaddue.moe-118eb7f2b25b3f9d6e9c25e02ccc15401286fd22.tar.xz
due.moe-118eb7f2b25b3f9d6e9c25e02ccc15401286fd22.zip
fix(service-worker): only show default notification if client visible
-rw-r--r--src/service-worker.ts7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/service-worker.ts b/src/service-worker.ts
index 18c839b1..0de69bdf 100644
--- a/src/service-worker.ts
+++ b/src/service-worker.ts
@@ -127,7 +127,12 @@ sw.addEventListener('push', async (event: PushEvent) => {
console.error(error);
}
- if (navigator.userAgent.includes('Chrome')) {
+ if (
+ navigator.userAgent.includes('Chrome') &&
+ !(await sw.clients.matchAll({ type: 'window', includeUncontrolled: true })).some(
+ (client) => client.visibilityState === 'visible'
+ )
+ ) {
await sw.registration.showNotification('due.moe', {
body: 'No new notifications',
icon: '/favicon-196x196.png',