Add web push notifications for new inbox items

This commit is contained in:
Ian Gulliver
2026-10-14 21:25:01 -07:00
parent 01c60d6618
commit 8e4c40eb5f
40 changed files with 1724 additions and 202 deletions
+28
View File
@@ -0,0 +1,28 @@
"use strict";
const sw = self;
sw.addEventListener("install", () => {
void sw.skipWaiting();
});
sw.addEventListener("activate", (e) => {
e.waitUntil(sw.clients.claim());
});
sw.addEventListener("push", (e) => {
const msg = e.data?.json();
e.waitUntil(sw.registration.showNotification(msg.title, { body: msg.body, data: { url: msg.url } }));
});
sw.addEventListener("notificationclick", (e) => {
e.notification.close();
const url = e.notification.data.url;
e.waitUntil(openTask(url));
});
async function openTask(url) {
const windows = await sw.clients.matchAll({ type: "window", includeUncontrolled: true });
const win = windows[0];
if (!win) {
await sw.clients.openWindow(url);
return;
}
win.postMessage({ open: url });
await win.focus();
}
//# sourceMappingURL=sw.js.map