diff --git a/pwabuilder-sw.js b/pwabuilder-sw.js index df60e1e6..b25df39e 100644 --- a/pwabuilder-sw.js +++ b/pwabuilder-sw.js @@ -2,8 +2,9 @@ 'use strict'; // App version number - ENSURE IT MATCHES VALUE IN init.js -// DEV: Find a way to set this programmatically -const appVersion = '1.1.3'; +// DEV: Changing this will cause the browser to recognize that the Service Worker has changed, and it will download and +// install a new copy +const appVersion = '1.1.4'; // Kiwix ZIM Archive Download Server in regex form // DEV: The server URL is defined in init.js, but is not available to us in SW @@ -162,24 +163,6 @@ function intercept(event) { if (event.request.method !== "GET") return; event.respondWith( fromCache(event.request).then(function (response) { - // This is where we call the server to check for any new release - if (/\/init\.js$/i.test(event.request.url) && !excludedURLSchema.test(event.request.url)) { - event.waitUntil( - fetch(event.request).then(function (response) { - // Get response text - return response.text().then(function (text) { - var version = appVersion; - var versionMatch = text.match(/params\[.version.]\s*=\s*["']([^"]+)["']/); - if (versionMatch) version = versionMatch[1]; - if (version !== appVersion) { - console.log('[SW] New version of PWA found:' + version); - } - // Cache flag to app.js to update SW - return updateCache('version', new Response(version)); - }); - }) - ); - } console.log('[SW] Supplying ' + event.request.url + ' from CACHE...'); return response; }, diff --git a/www/js/app.js b/www/js/app.js index c4f13054..b6233869 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -754,27 +754,6 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett divInstall1.style.display = 'none'; } } - // Check for upgrade of PWA - if(!params.upgradeNeeded && 'serviceWorker' in navigator && /https?:/i.test(window.location.protocol) && activeBtn === 'btnConfigure') { - cache.cacheAPI('version', function(value) { - if (value && value !== params.version) { - params.upgradeNeeded = true; - var alertHTML = - '
' + - '×' + - 'An update was found: Kiwix JS Windows will be updated to version ' + value + ' on next app launch' + - '
'; - var alertBoxHeader = document.getElementById('alertBoxHeader'); - alertBoxHeader.innerHTML = alertHTML; - alertBoxHeader.style.display = 'block'; - navigator.serviceWorker.getRegistrations().then(function (registrations) { - registrations.forEach(function (registration) { - registration.update(); - }); - }); - } - }); - } setTimeout(resizeIFrame, 100); } diff --git a/www/js/init.js b/www/js/init.js index 68a356d1..19263c28 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -49,7 +49,7 @@ var params = {}; */ var appstate = {}; /******** UPDATE VERSION IN pwabuilder-sw.js TO MATCH VERSION *******/ -params['version'] = "1.1.3"; //DEV: Manually update this version when there is a new release: it is compared to the Settings Store "version" in order to show first-time info, and the cookie is updated in app.js +params['version'] = "1.1.4"; //DEV: Manually update this version when there is a new release: it is compared to the Settings Store "version" in order to show first-time info, and the cookie is updated in app.js /******* UPDATE THIS ^^^^^^ IN serveice worker!! ********************/ params['packagedFile'] = "wikipedia_en_100_maxi.zim"; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename (for split files, give the first chunk *.zimaa) and place file(s) in default storage params['archivePath'] = "archives"; //The directory containing the packaged archive(s) (relative to app's root directory)