const CACHE = 'life-os-shell-v1.5.0'; const SHELL = [ '/', '/index.html', '/manifest.webmanifest', '/life-os-icon.svg', '/boot-guard.js', '/i18n.js', '/tasks.js?v=1.5.0', '/calendar.js?v=1.5.0', '/i18n-renderers.js', '/addons.js?v=1.5.0' ]; self.addEventListener('install', event => { event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(SHELL)).then(() => self.skipWaiting())); }); self.addEventListener('activate', event => { event.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(key => key.startsWith('life-os-shell-') && key !== CACHE).map(key => caches.delete(key)))).then(() => self.clients.claim())); }); self.addEventListener('fetch', event => { const request = event.request; if (request.method !== 'GET' || new URL(request.url).origin !== self.location.origin) return; const url = new URL(request.url); if (url.pathname.startsWith('/api/')) return; if (request.mode === 'navigate') { event.respondWith(fetch(request).then(response => { const copy = response.clone(); caches.open(CACHE).then(cache => cache.put('/index.html', copy)); return response; }).catch(() => caches.match('/index.html'))); return; } event.respondWith(caches.match(request).then(cached => cached || fetch(request).then(response => { if (response.ok) caches.open(CACHE).then(cache => cache.put(request, response.clone())); return response; }))); });