c812a1a595
Integrate the remote firmware workbench, OTA delivery, and timed mode schedules while preserving the local N7 scene and runtime changes.
113 lines
4.1 KiB
JavaScript
113 lines
4.1 KiB
JavaScript
const CACHE_VERSION = "cognitive-agent-pad-v322-n7-firmware-merge";
|
|
const SHELL_CACHE = `${CACHE_VERSION}-shell`;
|
|
const RUNTIME_CACHE = `${CACHE_VERSION}-runtime`;
|
|
const APP_SHELL = [
|
|
"/",
|
|
"/index.html",
|
|
"/styles.css?v=dual-seat-23",
|
|
"/network.js?v=android-pad-2",
|
|
"/app.js?v=dual-seat-145-n7-dispatch",
|
|
"/gesture-control.js?v=android-pad-9",
|
|
"/pwa.js?v=android-pad-3",
|
|
"/console-v2.css?v=delivery-state-69",
|
|
"/console-v2.js?v=local-first-77-performance",
|
|
"/self-extension.css?v=pet-settings-52",
|
|
"/self-extension.js?v=pet-settings-53-performance",
|
|
"/speech-input.css?v=sensevoice-7",
|
|
"/speech-input.js?v=sensevoice-13",
|
|
"/speech-audio-worklet.js?v=sensevoice-5",
|
|
"/assistant-chat.css?v=codex-assistant-29",
|
|
"/assistant-chat.js?v=codex-assistant-34",
|
|
"/energy-monitor.css?v=energy-monitor-4",
|
|
"/energy-monitor.js?v=energy-monitor-5-performance",
|
|
"/ui-consistency.css?v=spatial-ui-8",
|
|
"/codepen-glass-theme.css?v=creative-cloud-6-performance",
|
|
"/vue-ui.js?v=vue-presentation-3",
|
|
"/firmware-workbench-entry.css?v=1",
|
|
"/firmware-workbench-entry.js?v=2",
|
|
"/firmware-workbench.html",
|
|
"/firmware-workbench.css?v=5",
|
|
"/firmware-workbench.js?v=3",
|
|
"/assets/pets/self-extension-cat.png?v=3",
|
|
"/assets/pets/self-extension-cat-entrance.png?v=3",
|
|
"/manifest.webmanifest",
|
|
"/icons/app-icon-192.png",
|
|
"/icons/app-icon-512.png",
|
|
"/vendor/lucide/0.468.0/lucide.min.js",
|
|
"/vendor/vue/3.5.21/vue.runtime.global.prod.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.skipWaiting())
|
|
.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 shellCache = await caches.open(SHELL_CACHE);
|
|
const runtimeCache = await caches.open(RUNTIME_CACHE);
|
|
const cached = (await shellCache.match(request)) || (await runtimeCache.match(request));
|
|
if (cached) return cached;
|
|
const response = await fetch(request);
|
|
if (response.ok) {
|
|
await runtimeCache.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) {
|
|
const shellCache = await caches.open(SHELL_CACHE);
|
|
const runtimeCache = await caches.open(RUNTIME_CACHE);
|
|
return (await runtimeCache.match("/index.html"))
|
|
|| (await shellCache.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();
|
|
});
|