baton/frontend/sw.js
Gros Frumos cb89a90771 fix: viewport safe-area-inset for iOS PWA + disable pinch zoom
Topbar (avatar, network indicator) was hidden behind iOS status bar
in standalone PWA mode. Added safe-area-inset-top padding to topbar.
Disabled user-scalable to prevent accidental zoom.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-21 16:40:30 +02:00

60 lines
1.5 KiB
JavaScript

'use strict';
const CACHE_NAME = 'baton-v4';
// App shell assets to precache
const APP_SHELL = [
'/',
'/index.html',
'/app.js',
'/style.css',
'/manifest.json',
'/icons/icon-192.png',
'/icons/icon-512.png',
];
// Install: precache app shell + skipWaiting so new SW activates immediately
self.addEventListener('install', (event) => {
self.skipWaiting();
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL))
);
});
// Activate: delete stale caches + claim open clients (decision: skipWaiting + clients.claim)
self.addEventListener('activate', (event) => {
event.waitUntil(
caches
.keys()
.then((keys) =>
Promise.all(
keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k))
)
)
.then(() => self.clients.claim())
);
});
// Fetch: cache-first for app shell; API calls pass through to network
self.addEventListener('fetch', (event) => {
if (event.request.method !== 'GET') return;
const url = new URL(event.request.url);
// Never intercept API calls — they must always reach the server
if (url.pathname.startsWith('/api/')) return;
event.respondWith(
caches.match(event.request).then((cached) => {
if (cached) return cached;
return fetch(event.request).then((response) => {
if (response && response.status === 200) {
const clone = response.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
}
return response;
});
})
);
});