aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-07-25 04:10:39 -0700
committerFuwn <[email protected]>2024-07-25 04:10:39 -0700
commit0ef20bd8d9ab0f12ace75cdbbd0e5767a5f40d3a (patch)
tree9608a8e1da19826ac7d005f688d6dec80621cc25 /src
parentfix(actions): correct trigger path (diff)
downloaddue.moe-0ef20bd8d9ab0f12ace75cdbbd0e5767a5f40d3a.tar.xz
due.moe-0ef20bd8d9ab0f12ace75cdbbd0e5767a5f40d3a.zip
fix(service-worker): show default notification for chrome
Diffstat (limited to 'src')
-rw-r--r--src/service-worker.ts30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/service-worker.ts b/src/service-worker.ts
index 21de63a2..d7cc2cdd 100644
--- a/src/service-worker.ts
+++ b/src/service-worker.ts
@@ -125,17 +125,25 @@ sw.addEventListener('push', async (event: PushEvent) => {
console.error(error);
}
- // Ref. https://github.com/firebase/quickstart-js/issues/126#issuecomment-504081087
- return new Promise((resolve) => {
- (resolve as unknown as () => void)();
- setTimeout(() => {
- sw.registration.getNotifications().then((notifications) => {
- notifications.forEach((notification) => {
- if (notification.tag !== 'notification') notification.close();
- });
- });
- }, 10);
- });
+ if (navigator.userAgent.includes('Chrome')) {
+ sw.registration.showNotification('due.moe', {
+ body: 'No new notifications',
+ icon: '/favicon-196x196.png',
+ tag: 'notification-1'
+ });
+
+ // Ref. https://github.com/firebase/quickstart-js/issues/126#issuecomment-504081087
+ new Promise((resolve) => {
+ (resolve as unknown as () => void)();
+ setTimeout(
+ () =>
+ sw.registration
+ .getNotifications()
+ .then((notifications) => notifications.forEach((notification) => notification.close())),
+ 10
+ );
+ });
+ }
});
sw.addEventListener('notificationclick', (event: NotificationEvent) => {