28 lines
841 B
JavaScript
28 lines
841 B
JavaScript
"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
|