/* 現場ReNote — PWA(設置フォルダ相対) */ const CACHE = 'genba-note-pwa-2.1'; const SHELL = [ './index.html', './genbatabs.html', './setup.html', './genba-note-core.js', './progress-vendor-blocks.js', './design-tokens.css', './genba-ui.css', './manifest.webmanifest', './icon-192.png', './icon-512.png', './icon-maskable-512.png', './apple-touch-icon.png', './ReNote_logo_144.png', './README.md', './tenants.json', './assets/genbatabs-license.css', './assets/genbatabs-license.js', './progress.html', './labor.html', './daily.html', './quality.html', './checklist/precheck.html', './checklist/spec.html', './roster/gc.html', './roster/crew.html', './roster/leaders.html' ]; self.addEventListener('install', (e) => { e.waitUntil( caches.open(CACHE).then((c) => c.addAll(SHELL)).then(() => self.skipWaiting()) ); }); let SCOPE_PREFIX = ''; self.addEventListener('activate', (e) => { e.waitUntil( caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))) ).then(() => { SCOPE_PREFIX = self.registration.scope; return self.clients.claim(); }) ); }); self.addEventListener('fetch', (e) => { if (e.request.method !== 'GET') return; const url = new URL(e.request.url); if (url.origin !== self.location.origin) return; const scope = SCOPE_PREFIX || (self.registration && self.registration.scope) || ''; if (scope && !url.href.startsWith(scope)) return; e.respondWith( fetch(e.request) .then((res) => { if (res && res.status === 200) { const copy = res.clone(); caches.open(CACHE).then((c) => c.put(e.request, copy)); } return res; }) .catch(() => caches.match(e.request).then((r) => r || caches.match('./index.html'))) ); });