SLC_Game/04_Tablet-Quiz/app/sw.js
breitenbach76 43320be1fb Companion-App: finale Action-Card-Grafiken eingebunden (29/30)
- 29 PNGs als app/cards/s<service>-c<change>.png (PNG-Nr n -> Service floor(n/5),
  Change n%5). Karten-Screen zeigt jetzt die finale Grafik statt Text.
- Helfer cardImg()/cardMedia(); Text-Fallback fuer die noch fehlende Karte
  s0-c0 ("Open Source von oben!").
- Service Worker cacht die Karten-Grafiken vorab (Offline), CACHE -> v2.
- README-Umsetzungsstand ergaenzt.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-06 14:12:20 +02:00

40 lines
1.2 KiB
JavaScript

/* Service Worker — SLC-Workshop Companion (App-Shell, offline-first) */
const CACHE = "slc-companion-v2";
const SHELL = ["./", "index.html", "manifest.webmanifest", "icon.svg"];
// Action-Card-Grafiken (cards/s<service>-c<change>.png) fuer Offline vorab cachen.
const CARDS = [];
for (let s = 0; s <= 5; s++) for (let c = 0; c <= 4; c++) {
if (s === 0 && c === 0) continue; // s0-c0 fehlt (Text-Fallback)
CARDS.push(`cards/s${s}-c${c}.png`);
}
const ASSETS = SHELL.concat(CARDS);
self.addEventListener("install", (e) => {
e.waitUntil(
caches.open(CACHE).then((c) => c.addAll(ASSETS)).then(() => self.skipWaiting())
);
});
self.addEventListener("activate", (e) => {
e.waitUntil(
caches.keys()
.then((ks) => Promise.all(ks.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((resp) => {
const copy = resp.clone();
caches.open(CACHE).then((c) => c.put(e.request, copy));
return resp;
})
.catch(() => caches.match("index.html"))
)
);
});