diff --git a/public/assets/pwa/shipping-note-tablet-sw.js b/public/assets/pwa/shipping-note-tablet-sw.js index 5c12d8bb1..cf42313e6 100644 --- a/public/assets/pwa/shipping-note-tablet-sw.js +++ b/public/assets/pwa/shipping-note-tablet-sw.js @@ -1,6 +1,5 @@ -const CACHE_NAME = 'lager-system-cache-v1'; +const CACHE_NAME = 'lager-system-cache-v3'; const urlsToCache = [ - '.', 'https://cdn.jsdelivr.net/npm/vue@3.4.27/dist/vue.global.min.js', 'https://cdn.tailwindcss.com', '/assets/images/xinon-full.png', @@ -9,23 +8,18 @@ const urlsToCache = [ ]; self.addEventListener('install', event => { - event.waitUntil( - caches.open(CACHE_NAME).then(cache => cache.addAll(urlsToCache)) - ); + event.waitUntil(caches.open(CACHE_NAME).then(cache => cache.addAll(urlsToCache))); }); self.addEventListener('fetch', event => { - event.respondWith( - caches.match(event.request).then(response => response || fetch(event.request)) - ); + event.respondWith(caches.match(event.request).then(response => response || fetch(event.request))); }); self.addEventListener('activate', event => { - const cacheWhitelist = [CACHE_NAME]; event.waitUntil( caches.keys().then(cacheNames => Promise.all( cacheNames - .filter(cacheName => !cacheWhitelist.includes(cacheName)) + .filter(cacheName => cacheName !== CACHE_NAME) .map(cacheName => caches.delete(cacheName)) )) ); diff --git a/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js b/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js index 3b953f031..45c01e557 100644 --- a/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js +++ b/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js @@ -502,14 +502,15 @@ Vue.component('warehouse-shipping-note', { } }) -window.addEventListener('DOMContentLoaded', () => { - if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('/WarehouseShippingNote/sw', {scope: '/'}) - .then(registration => { - console.log('Patching PWA Service Worker registered with scope:', registration.scope); - }) - .catch(error => { - console.error('Patching PWA Service Worker registration failed:', error); - }); +let hiddenTime = null; +const RELOAD_AFTER_SECONDS = 300; +document.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'hidden') { + hiddenTime = new Date(); + } else if (document.visibilityState === 'visible' && hiddenTime) { + const secondsElapsed = (new Date() - hiddenTime) / 1000; + if (secondsElapsed > RELOAD_AFTER_SECONDS) { + window.location.reload(); + } } -}) \ No newline at end of file +}); \ No newline at end of file