add app, fix ble, use flash

This commit is contained in:
zyphlar
2026-07-04 03:28:14 -07:00
parent e6a2a65b82
commit 24de5d8d39
13 changed files with 1028 additions and 249 deletions
+31
View File
@@ -0,0 +1,31 @@
// sw.js — minimal offline cache so the PWA launches without a network.
const CACHE = 'babymobile-v2';
const ASSETS = [
'./', './index.html', './styles.css',
'./app.js', './ble.js', './wav.js',
'./manifest.webmanifest', './icon.svg',
];
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((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
.then(() => self.clients.claim())
);
});
// Cache-first for app shell; network passthrough otherwise.
self.addEventListener('fetch', (e) => {
const url = new URL(e.request.url);
if (e.request.method !== 'GET' || url.origin !== location.origin) 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(() => hit))
);
});