feat: turn into a pwa

This commit is contained in:
Julien Calixte
2026-03-23 19:25:34 +01:00
parent 1afe86b79a
commit da1f3566c2
6 changed files with 99 additions and 0 deletions

27
app/static/sw.js Normal file
View File

@@ -0,0 +1,27 @@
const CACHE = 'apoena-v1';
const PRECACHE = ['/', '/worker.js', '/manifest.json', '/icon.svg', '/icon-maskable.svg'];
self.addEventListener('install', e => {
e.waitUntil(caches.open(CACHE).then(c => c.addAll(PRECACHE)));
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 => {
const url = new URL(e.request.url);
// Pass through API calls
if (url.pathname === '/extract-audio') return;
e.respondWith(
caches.match(e.request).then(cached => cached || fetch(e.request))
);
});