const CACHE_VERSION = 'duimstok-v3'; const APP_SHELL = [ './', './index.html', './manifest.webmanifest', './icons/icon.svg', './css/base.css', './css/overview.css', './css/form.css', './css/modals.css', './css/install.css', './css/responsive.css', './js/namespace.js', './js/main.js', '../src/Domain/sectionMap.js', '../src/Domain/scoring.js', '../src/Domain/inspectionTypes.js', '../src/Domain/orderParser.js', '../src/Infrastructure/utils.js', '../src/Infrastructure/geolocation.js', '../src/Infrastructure/db.js', '../src/Infrastructure/persistentStorage.js', '../src/Infrastructure/seedOrders.js', '../src/Infrastructure/csvLoader.js', '../src/Application/state.js', '../src/Application/persistence.js', '../src/Application/screens.js', '../src/Application/photoService.js', '../src/Application/inspectionForm.js', '../src/Application/orderOverview.js', '../src/Application/xmlImport.js', '../src/Application/exportService.js', '../src/Application/pwa.js', '../src/Application/installScreen.js' ]; self.addEventListener('install', (event) => { event.waitUntil( caches.open(CACHE_VERSION).then((cache) => cache.addAll(APP_SHELL)) ); self.skipWaiting(); }); self.addEventListener('activate', (event) => { event.waitUntil( caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE_VERSION).map((k) => caches.delete(k))) ).then(() => self.clients.claim()) ); }); self.addEventListener('fetch', (event) => { const req = event.request; if (req.method !== 'GET') return; const url = new URL(req.url); if (url.origin !== self.location.origin) return; event.respondWith( caches.match(req).then((cached) => { if (cached) return cached; return fetch(req).then((resp) => { if (resp && resp.status === 200 && resp.type === 'basic') { const copy = resp.clone(); caches.open(CACHE_VERSION).then((cache) => cache.put(req, copy)); } return resp; }).catch(() => { if (req.mode === 'navigate') return caches.match('./index.html'); return new Response('', { status: 504, statusText: 'Offline' }); }); }) ); });