Make changes automatic

Former-commit-id: 5f0d0eea402ed512f11a2ef2e1cecba473c28361 [formerly f608505007d83f52969d2b237ae742455ca89bf3 [formerly 9385c3d3b2c7fa9f547397f604ebd09254656f8f]]
Former-commit-id: 11ef793495950bdb884b1a29e75c263c0714b29e
Former-commit-id: 761584dcc3d6a1119ff1f3d993141874f5a6f1b1
This commit is contained in:
Jaifroid 2021-01-10 10:25:42 +00:00
parent 5972cf3502
commit fb68ec027c
3 changed files with 4 additions and 42 deletions

View File

@ -2,8 +2,9 @@
'use strict'; 'use strict';
// App version number - ENSURE IT MATCHES VALUE IN init.js // App version number - ENSURE IT MATCHES VALUE IN init.js
// DEV: Find a way to set this programmatically // DEV: Changing this will cause the browser to recognize that the Service Worker has changed, and it will download and
const appVersion = '1.1.3'; // install a new copy
const appVersion = '1.1.4';
// Kiwix ZIM Archive Download Server in regex form // 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 // 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; if (event.request.method !== "GET") return;
event.respondWith( event.respondWith(
fromCache(event.request).then(function (response) { 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...'); console.log('[SW] Supplying ' + event.request.url + ' from CACHE...');
return response; return response;
}, },

View File

@ -754,27 +754,6 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
divInstall1.style.display = 'none'; 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 =
'<div id="activeContent" class="alert alert-warning alert-dismissible fade in" style="margin-bottom: 0;">' +
'<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>' +
'<strong>An update was found:</strong> Kiwix JS Windows will be updated to version ' + value + ' on next app launch' +
'</div>';
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); setTimeout(resizeIFrame, 100);
} }

View File

@ -49,7 +49,7 @@ var params = {};
*/ */
var appstate = {}; var appstate = {};
/******** UPDATE VERSION IN pwabuilder-sw.js TO MATCH VERSION *******/ /******** 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!! ********************/ /******* 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['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) params['archivePath'] = "archives"; //The directory containing the packaged archive(s) (relative to app's root directory)