// Inkwell service worker: makes the web app installable and shows a page when a // navigation has no network. Deliberately not offline-first (the desktop and Android // apps are): it caches only the offline page, so an installed copy is always the live // web app. const CACHE = "inkwell-shell-v1"; const OFFLINE_URL = "/offline.html"; self.addEventListener("install", (event) => { event.waitUntil( caches .open(CACHE) .then((cache) => cache.add(OFFLINE_URL)) .then(() => self.skipWaiting()), ); }); self.addEventListener("activate", (event) => { event.waitUntil( caches .keys() .then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))) .then(() => self.clients.claim()), ); }); // Only intercept page navigations: try the network, fall back to the cached // offline page when the server is unreachable. All other requests (hashed // assets, /api/*) are left untouched and hit the network normally. self.addEventListener("fetch", (event) => { if (event.request.mode !== "navigate") return; event.respondWith(fetch(event.request).catch(() => caches.match(OFFLINE_URL))); });