aggiornamento
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.5.4/workbox-sw.js');
|
||||
|
||||
import { cleanupOutdatedCaches, precacheAndRoute } from 'workbox-precaching';
|
||||
import { registerRoute } from 'workbox-routing';
|
||||
import { clientsClaim, setCacheNameDetails, skipWaiting } from 'workbox-core';
|
||||
@@ -16,32 +14,16 @@ import { ExpirationPlugin } from 'workbox-expiration';
|
||||
|
||||
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
||||
|
||||
|
||||
self.addEventListener('install', () => self.skipWaiting());
|
||||
self.addEventListener('activate', (event) => {
|
||||
// console.log('CLAIM');
|
||||
//event.waitUntil(self.clients.claim())
|
||||
|
||||
event.waitUntil(async () => {
|
||||
// Check for a new service worker version
|
||||
const registration = await navigator.serviceWorker.getRegistration();
|
||||
if (registration && registration.waiting) {
|
||||
// A new service worker is waiting, trigger a page reload
|
||||
await registration.waiting.postMessage({ type: 'SKIP_WAITING' });
|
||||
self.skipWaiting();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const VersioneApp = '1.0.42';
|
||||
self.addEventListener('activate', (event) => event.waitUntil(self.clients.claim()));
|
||||
|
||||
const VersioneApp = '1.0.46';
|
||||
|
||||
console.log(' [ VER-' + VersioneApp + ' ] _---------________------ PAO: this is my custom service worker');
|
||||
|
||||
importScripts('js/idb.js', 'js/storage.js');
|
||||
importScripts('js/idb.js', 'js/storage.js', 'js/workbox-sw.js');
|
||||
|
||||
let port = self.location.hostname.startsWith('test') ? 3001 : 3000;
|
||||
console.log('SW- app ver ' + VersioneApp + ' on port ' + port);
|
||||
|
||||
// Function helpers
|
||||
async function writeData(table, data) {
|
||||
@@ -153,7 +135,7 @@ if (workbox) {
|
||||
const syncStore = {};
|
||||
self.addEventListener('message', event => {
|
||||
if (event.data && (event.data.type === 'SKIP_WAITING' || event.data.action === 'skipWaiting')) {
|
||||
window.location.reload();
|
||||
self.skipWaiting();
|
||||
}
|
||||
if (event.data.type === 'sync') {
|
||||
console.log('addEventListener - message');
|
||||
|
||||
@@ -13,10 +13,6 @@ register(process.env.SERVICE_WORKER_FILE ? process.env.SERVICE_WORKER_FILE : '',
|
||||
|
||||
registered(registration) { // registration -> a ServiceWorkerRegistration instance
|
||||
console.log('REGISTERED::: !!!', process.env.SERVICE_WORKER_FILE)
|
||||
setInterval(() => {
|
||||
registration.update()
|
||||
}, 5000) // every 5 seconds
|
||||
|
||||
},
|
||||
cached(registration) {
|
||||
console.log('CACHED::: Content has been cached for offline use.')
|
||||
@@ -30,7 +26,6 @@ register(process.env.SERVICE_WORKER_FILE ? process.env.SERVICE_WORKER_FILE : '',
|
||||
new CustomEvent('swUpdated', { detail: registration })
|
||||
)
|
||||
console.log('New content is available; please refresh.')
|
||||
// window.location.reload();
|
||||
},
|
||||
offline() {
|
||||
console.log('No internet connection found. App is running in offline mode.')
|
||||
@@ -40,6 +35,4 @@ register(process.env.SERVICE_WORKER_FILE ? process.env.SERVICE_WORKER_FILE : '',
|
||||
},
|
||||
});
|
||||
|
||||
// ServiceWorkerRegistration: https://developer.mozilla.org/enUs/docs/Web/API/ServiceWorkerRegistration
|
||||
|
||||
// "build": "quasar build -m pwa && workbox generateSW workbox-config.js",
|
||||
// ServiceWorkerRegistration: https://developer.mozilla.org/enUs/docs/Web/API/ServiceWorkerRegistration
|
||||
Reference in New Issue
Block a user