mirror of
https://github.com/multipleof4/devsune.git
synced 2026-01-14 00:17:56 +00:00
This build was committed by a bot.
This commit is contained in:
16
docs/sw.js
16
docs/sw.js
@@ -1,15 +1,19 @@
|
||||
const log = (...a) => console.log("[SW]", ...a);
|
||||
const V = "1";
|
||||
const send = (a) => self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((cs) => cs.forEach((c) => c.postMessage(a)));
|
||||
self.addEventListener("install", (e) => {
|
||||
log("install");
|
||||
self.skipWaiting();
|
||||
});
|
||||
self.addEventListener("activate", (e) => {
|
||||
log("activate");
|
||||
e.waitUntil(self.clients.claim());
|
||||
e.waitUntil((async () => {
|
||||
await self.clients.claim();
|
||||
await send({ type: "SW_ACTIVE", v: V, ts: Date.now() });
|
||||
})());
|
||||
});
|
||||
self.addEventListener("fetch", (e) => {
|
||||
if (e.request.mode === "navigate") log("navigate", e.request.url);
|
||||
if (e.request.mode === "navigate") send({ type: "SW_NAVIGATE", url: e.request.url, ts: Date.now() });
|
||||
});
|
||||
self.addEventListener("message", (e) => {
|
||||
log("message", e.data);
|
||||
if (e.data && e.data.type === "PING") {
|
||||
(e.source || null)?.postMessage({ type: "PONG", v: V, ts: Date.now() }) || send({ type: "PONG", v: V, ts: Date.now() });
|
||||
} else send({ type: "SW_MESSAGE", data: e.data, ts: Date.now() });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user