From fb68ec027c8689ea8aae38d40f5fea3a94b9a60e Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sun, 10 Jan 2021 10:25:42 +0000 Subject: [PATCH] Make changes automatic Former-commit-id: 5f0d0eea402ed512f11a2ef2e1cecba473c28361 [formerly f608505007d83f52969d2b237ae742455ca89bf3 [formerly 9385c3d3b2c7fa9f547397f604ebd09254656f8f]] Former-commit-id: 11ef793495950bdb884b1a29e75c263c0714b29e Former-commit-id: 761584dcc3d6a1119ff1f3d993141874f5a6f1b1 --- pwabuilder-sw.js | 23 +++-------------------- www/js/app.js | 21 --------------------- www/js/init.js | 2 +- 3 files changed, 4 insertions(+), 42 deletions(-) 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)