rastrillo / aviso Public

Clone
git clone https://amadan.net/rastrillo/aviso

Plain git — no account needed to clone.

Download

Download this file

1// The app's worker, as SKILL.md shows it. Lifecycle is the app's:
2// nothing here calls skipWaiting or clients.claim either, because this
3// example has nothing to claim.
4importScripts("/static/aviso/aviso-sw.js");
5
6const post = (body) => fetch("/aviso/subscribe", {
7 method: "POST", credentials: "same-origin", mode: "same-origin", redirect: "error",
8 headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),
9});
10
11self.addEventListener("push", (e) => e.waitUntil(AvisoSW.handlePush(e, {
12 fallback: () => ({ title: "aviso example", options: { body: "Something happened.", data: { url: "/" } } }),
13})));
14
15self.addEventListener("notificationclick", (e) => e.waitUntil(AvisoSW.handleClick(e, { fallbackURL: "/" })));
16
17self.addEventListener("pushsubscriptionchange", (e) => e.waitUntil(AvisoSW.handleSubscriptionChange(e, {
18 // Fetched on demand: a terminated worker forgets its variables.
19 publicKey: () => fetch("/aviso/public-key").then((r) => r.json()).then((j) => j.publicKey),
20 save: post,
21})));
22