95 lines
3.2 KiB
JavaScript
95 lines
3.2 KiB
JavaScript
const CACHE_VERSION = "cognitive-agent-pad-v119";
|
|
const SHELL_CACHE = `${CACHE_VERSION}-shell`;
|
|
const RUNTIME_CACHE = `${CACHE_VERSION}-runtime`;
|
|
const APP_SHELL = [
|
|
"/",
|
|
"/index.html",
|
|
"/styles.css?v=dual-seat-9",
|
|
"/network.js?v=android-pad-1",
|
|
"/app.js?v=dual-seat-82",
|
|
"/gesture-control.js?v=android-pad-7",
|
|
"/pwa.js?v=android-pad-1",
|
|
"/console-v2.css?v=desktop-refactor-106",
|
|
"/console-v2.js?v=desktop-refactor-35",
|
|
"/self-extension.css?v=extension-19",
|
|
"/self-extension.js?v=extension-21",
|
|
"/self-calibration.css?v=calibration-12",
|
|
"/self-calibration.js?v=calibration-8",
|
|
"/self-repair.css?v=repair-21",
|
|
"/self-repair.js?v=repair-21",
|
|
"/self-repair-seat3d.js?v=repair-21",
|
|
"/assets/models/n7_seat.glb?v=e7f50f03",
|
|
"/manifest.webmanifest",
|
|
"/icons/app-icon-192.png",
|
|
"/icons/app-icon-512.png",
|
|
"/vendor/lucide/0.468.0/lucide.min.js",
|
|
"/vendor/three/0.147.0/three.min.js",
|
|
"/vendor/three/0.147.0/fflate.min.js",
|
|
"/vendor/three/0.147.0/FBXLoader.js",
|
|
"/vendor/mediapipe/tasks-vision/0.10.14/vision_bundle.mjs",
|
|
"/vendor/mediapipe/tasks-vision/0.10.14/wasm/vision_wasm_internal.js",
|
|
"/vendor/mediapipe/tasks-vision/0.10.14/wasm/vision_wasm_internal.wasm",
|
|
"/vendor/mediapipe/tasks-vision/0.10.14/wasm/vision_wasm_nosimd_internal.js",
|
|
"/vendor/mediapipe/tasks-vision/0.10.14/wasm/vision_wasm_nosimd_internal.wasm"
|
|
];
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(
|
|
caches.open(SHELL_CACHE)
|
|
.then((cache) => cache.addAll(APP_SHELL))
|
|
.then(() => self.clients.matchAll({ includeUncontrolled: true }))
|
|
.then((clients) => clients.forEach((client) => client.postMessage({ type: "OFFLINE_READY" })))
|
|
);
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches.keys()
|
|
.then((keys) => Promise.all(
|
|
keys.filter((key) => key.startsWith("cognitive-agent-pad-")
|
|
&& ![SHELL_CACHE, RUNTIME_CACHE].includes(key))
|
|
.map((key) => caches.delete(key))
|
|
))
|
|
.then(() => self.clients.claim())
|
|
);
|
|
});
|
|
|
|
async function cacheFirst(request) {
|
|
const cached = await caches.match(request);
|
|
if (cached) return cached;
|
|
const response = await fetch(request);
|
|
if (response.ok) {
|
|
const cache = await caches.open(RUNTIME_CACHE);
|
|
await cache.put(request, response.clone());
|
|
}
|
|
return response;
|
|
}
|
|
|
|
async function navigationResponse(request) {
|
|
try {
|
|
const response = await fetch(request);
|
|
if (response.ok) {
|
|
const cache = await caches.open(RUNTIME_CACHE);
|
|
await cache.put("/index.html", response.clone());
|
|
}
|
|
return response;
|
|
} catch (_error) {
|
|
return (await caches.match("/index.html")) || Response.error();
|
|
}
|
|
}
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
const url = new URL(event.request.url);
|
|
if (url.origin !== self.location.origin || event.request.method !== "GET") return;
|
|
if (event.request.mode === "navigate") {
|
|
event.respondWith(navigationResponse(event.request));
|
|
return;
|
|
}
|
|
if (url.pathname.startsWith("/api/") && url.pathname !== "/api/gesture/model") return;
|
|
event.respondWith(cacheFirst(event.request));
|
|
});
|
|
|
|
self.addEventListener("message", (event) => {
|
|
if (event.data?.type === "SKIP_WAITING") self.skipWaiting();
|
|
});
|