Add web push notifications for new inbox items
This commit is contained in:
Vendored
+28
@@ -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
|
||||
Reference in New Issue
Block a user