Download static/sw.js from Ashish-K/stepwise: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/Ashish-K/stepwise/resolve/main/static/sw.js
- Command line
-
hf download hf://spaces/Ashish-K/stepwise/static/sw.js
-
curl -L -o sw.js https://huggingface.co/spaces/Ashish-K/stepwise/resolve/main/static/sw.js
1.3 kB
| // StepWise service worker: notifications only. It does not cache pages, so the app is always fresh. | |
| self.addEventListener("install", () => self.skipWaiting()); | |
| self.addEventListener("activate", (e) => e.waitUntil(self.clients.claim())); | |
| self.addEventListener("push", (e) => { | |
| let d = {}; | |
| try { d = e.data ? e.data.json() : {}; } catch { d = { body: e.data ? e.data.text() : "" }; } | |
| e.waitUntil(self.registration.showNotification(d.title || "StepWise", { | |
| body: d.body || "", tag: d.tag || "stepwise", renotify: true, requireInteraction: d.tag === "quiz", | |
| icon: "icon-192.png", badge: "icon-192.png", vibrate: [250, 120, 250], data: { url: d.url || "/" }, | |
| })); | |
| }); | |
| self.addEventListener("notificationclick", (e) => { | |
| e.notification.close(); | |
| const url = new URL((e.notification.data && e.notification.data.url) || "/", self.location.origin).href; | |
| e.waitUntil((async () => { | |
| const wins = await self.clients.matchAll({ type: "window", includeUncontrolled: true }); | |
| for (const w of wins) { | |
| if (new URL(w.url).origin === self.location.origin) { | |
| await w.focus(); | |
| if (w.url !== url && "navigate" in w && !url.endsWith("/")) { try { await w.navigate(url); } catch {} } | |
| return; | |
| } | |
| } | |
| await self.clients.openWindow(url); | |
| })()); | |
| }); | |