Files
bgclock/public_html/sw.js
T
hansdezwartandClaude Opus 5 365605dd6c Default a fresh install to 3:00 + 12s
The reserve was already three minutes; only the delay moves, 15s to 12s,
which is the control both of the other presets use.

It is a default, not a migration: store.num only falls back when nothing
is saved, so anyone already carrying a bg.delay keeps it. Checked both
ways — an empty profile comes up with 12s and the 3m/12s preset already
lit, a profile holding 15000 comes up unchanged with 3m/15s lit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 17:00:50 +02:00

34 lines
981 B
JavaScript

/* Cache-first: once installed the clock never touches the network again. */
const CACHE = "bgclock-v10";
const FILES = [
"./",
"./index.html",
"./manifest.webmanifest",
"./icon-192.png",
"./icon-512.png",
"./icon-maskable-512.png"
];
self.addEventListener("install", (e) => {
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(FILES)).then(() => self.skipWaiting()));
});
self.addEventListener("activate", (e) => {
e.waitUntil(
caches.keys()
.then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
.then(() => self.clients.claim())
);
});
self.addEventListener("fetch", (e) => {
if (e.request.method !== "GET") return;
e.respondWith(
caches.match(e.request).then((hit) => hit || fetch(e.request).then((res) => {
const copy = res.clone();
caches.open(CACHE).then((c) => c.put(e.request, copy)).catch(() => {});
return res;
}).catch(() => caches.match("./index.html")))
);
});