Files
turn-up-arch/ui/public/sw.js
T
Sean Doran 8f8d9ac3fa feat: add React/Vite PWA web UI with FastAPI backend
- FastAPI + uvicorn server (turnup-ui) serving config API and static files
- React + TypeScript frontend: connection, global LEDs, per-knob/button
  cards, preset save/load/apply, toast notifications, dark theme
- Vite builds into src/turnup/ui/static/ so no Node.js needed at install time
- PWA assets (manifest, service worker, icon) in ui/public/
- turnup-ui.service systemd user unit; enabled globally via turnupd.install
- PKGBUILD: add python-fastapi + python-uvicorn deps, install UI service file
- pyproject.toml: ui extras group, turnup-ui entry point
2026-02-27 21:25:16 -05:00

32 lines
834 B
JavaScript

// Network-first SW: static assets are cached after first fetch;
// API calls always go to the network.
const CACHE = 'turnup-v1';
self.addEventListener('install', () => {
self.skipWaiting();
});
self.addEventListener('activate', (e) => {
e.waitUntil(
caches.keys().then((keys) =>
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
)
);
self.clients.claim();
});
self.addEventListener('fetch', (e) => {
// Always go network-first for API calls so the UI never serves stale data
if (e.request.url.includes('/api/')) return;
e.respondWith(
fetch(e.request)
.then((response) => {
const clone = response.clone();
caches.open(CACHE).then((c) => c.put(e.request, clone));
return response;
})
.catch(() => caches.match(e.request))
);
});