The clock buzzed on every turn change, on a flag and on the confirming second tap of Reset. Sound and the colour change carry all of it, so the vibration goes: buzz() and its four call sites, and the iOS README bullet that explained why the buzz was silent there — a platform difference that no longer exists now there are no haptics anywhere. Verified by stubbing navigator.vibrate and driving a turn change, a timeout and a confirmed reset: zero calls, while the turn still counted and the flag still fell. It also means the Android package can declare no permissions at all. VIBRATE was the only one it would have needed — there is no INTERNET either, since the whole clock ships inside the APK. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
34 lines
981 B
JavaScript
34 lines
981 B
JavaScript
/* Cache-first: once installed the clock never touches the network again. */
|
|
const CACHE = "bgclock-v15";
|
|
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")))
|
|
);
|
|
});
|