// ============================================================================== // Service Worker para OnEverControl PWA // Permite instalación en Android / Windows y aceleración de carga en red local // ============================================================================== const CACHE_NAME = 'onevercontrol-v0.6.2'; const STATIC_ASSETS = [ '/', '/index.html', '/manifest.json', '/favicon.ico', '/logo_mini.png', '/logo_os.png', '/icons/puesto-control.ico', '/icons/identificaciones.ico', '/icons/movimientos.ico' ]; self.addEventListener('install', (event) => { event.waitUntil( caches.open(CACHE_NAME).then((cache) => { return cache.addAll(STATIC_ASSETS).catch(() => {}); }) ); self.skipWaiting(); }); self.addEventListener('activate', (event) => { event.waitUntil( caches.keys().then((keys) => { return Promise.all( keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key)) ); }) ); self.clients.claim(); }); self.addEventListener('fetch', (event) => { const url = new URL(event.request.url); // No interceptar peticiones a la API backend ni WebSockets if (url.pathname.startsWith('/api') || url.pathname.startsWith('/ws')) { return; } event.respondWith( caches.match(event.request).then((cachedResponse) => { if (cachedResponse) { return cachedResponse; } return fetch(event.request).catch(() => { // Fallback a index.html en navegación SPA if (event.request.mode === 'navigate') { return caches.match('/'); } }); }) ); });