mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-10 12:53:54 -04:00
parent
7d64016a24
commit
b16a6cf388
@ -863,7 +863,14 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'cache', 'images
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for upgrade of PWA
|
// Check for upgrade of PWA
|
||||||
if (!params.upgradeNeeded && /^(?!.*Electron).*PWA/.test(params.appType) && activeBtn === 'btnConfigure') {
|
if (activeBtn === 'btnConfigure') checkPWAUpdate();
|
||||||
|
// Resize iframe
|
||||||
|
setTimeout(resizeIFrame, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a PWA update is available
|
||||||
|
function checkPWAUpdate() {
|
||||||
|
if (!params.upgradeNeeded && /^(?!.*Electron).*PWA/.test(params.appType)) {
|
||||||
caches.keys().then(function (keyList) {
|
caches.keys().then(function (keyList) {
|
||||||
var cachePrefix = cache.APPCACHE.replace(/^([^\d]+).+/, '$1');
|
var cachePrefix = cache.APPCACHE.replace(/^([^\d]+).+/, '$1');
|
||||||
document.getElementById('alertBoxPersistent').innerHTML = '';
|
document.getElementById('alertBoxPersistent').innerHTML = '';
|
||||||
@ -874,6 +881,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'cache', 'images
|
|||||||
// If we get here, then there is a kiwix cache key that does not match our version, i.e. a PWA-in-waiting
|
// If we get here, then there is a kiwix cache key that does not match our version, i.e. a PWA-in-waiting
|
||||||
var version = key.replace(cachePrefix, '');
|
var version = key.replace(cachePrefix, '');
|
||||||
var loadOrInstall = params.PWAInstalled ? 'install' : 'load';
|
var loadOrInstall = params.PWAInstalled ? 'install' : 'load';
|
||||||
|
params.upgradeNeeded = true;
|
||||||
uiUtil.showUpgradeReady(version, loadOrInstall);
|
uiUtil.showUpgradeReady(version, loadOrInstall);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -881,7 +889,6 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'cache', 'images
|
|||||||
var upgradeAlert = document.getElementById('upgradeAlert');
|
var upgradeAlert = document.getElementById('upgradeAlert');
|
||||||
if (upgradeAlert) upgradeAlert.style.display = 'block';
|
if (upgradeAlert) upgradeAlert.style.display = 'block';
|
||||||
}
|
}
|
||||||
setTimeout(resizeIFrame, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Electron callback listener if an update is found by main.js
|
// Electron callback listener if an update is found by main.js
|
||||||
@ -897,11 +904,13 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'cache', 'images
|
|||||||
params.isUWPStoreApp = /UWP/.test(params.appType) && Windows.ApplicationModel && Windows.ApplicationModel.Package &&
|
params.isUWPStoreApp = /UWP/.test(params.appType) && Windows.ApplicationModel && Windows.ApplicationModel.Package &&
|
||||||
!/Association.Kiwix/.test(Windows.ApplicationModel.Package.current.id.publisher);
|
!/Association.Kiwix/.test(Windows.ApplicationModel.Package.current.id.publisher);
|
||||||
// If Internet access is allowed, or it's a UWP Store app, or it's a PWA that is not Electron/NWJS ...
|
// If Internet access is allowed, or it's a UWP Store app, or it's a PWA that is not Electron/NWJS ...
|
||||||
if (params.allowInternetAccess || params.isUWPStoreApp || /^(?!.*(Electron|UWP)).*PWA/.test(params.appType))
|
if (params.allowInternetAccess || params.isUWPStoreApp || /^(?!.*(Electron|UWP)).*PWA/.test(params.appType)) {
|
||||||
updateCheck.style.display = 'none'; // ... hide the update check link
|
updateCheck.style.display = 'none'; // ... hide the update check link
|
||||||
|
}
|
||||||
|
// Function to check for updates from GitHub
|
||||||
function checkUpdateServer() {
|
function checkUpdateServer() {
|
||||||
if (!params.allowInternetAccess) {
|
if (!params.allowInternetAccess) {
|
||||||
console.log("The update check was blocked because the user has not allowed Internet access.")
|
console.log('The update check was blocked because the user has not allowed Internet access.')
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If it's a PWA that is not also an Electron/NWJS or UWP app, don't check for updates
|
// If it's a PWA that is not also an Electron/NWJS or UWP app, don't check for updates
|
||||||
@ -936,8 +945,13 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'cache', 'images
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Do check on startup
|
|
||||||
setTimeout(checkUpdateServer, 15000);
|
// Do update checks 10s after startup
|
||||||
|
setTimeout(function () {
|
||||||
|
console.log('Checking for updates to the PWA...');
|
||||||
|
checkPWAUpdate();
|
||||||
|
checkUpdateServer();
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
function setActiveBtn(activeBtn) {
|
function setActiveBtn(activeBtn) {
|
||||||
document.getElementById('btnHome').classList.remove("active");
|
document.getElementById('btnHome').classList.remove("active");
|
||||||
@ -1951,14 +1965,6 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'cache', 'images
|
|||||||
//Code below triggers display of modal info box if app is run for the first time, or it has been upgraded to new version
|
//Code below triggers display of modal info box if app is run for the first time, or it has been upgraded to new version
|
||||||
if (settingsStore.getItem('appVersion') !== params.appVersion) {
|
if (settingsStore.getItem('appVersion') !== params.appVersion) {
|
||||||
firstRun = true;
|
firstRun = true;
|
||||||
|
|
||||||
// If we have an update and the last selected archive is the packaged file, it is best not to preserve last read article
|
|
||||||
// var packagedFileStub = params.packagedFile.replace(/_[\d-]+\.zim\w?\w?$/, '');
|
|
||||||
// if (~params.storedFile.indexOf(packagedFileStub)) {
|
|
||||||
// params.lastPageVisit = '';
|
|
||||||
// params.storedFile = params.packagedFile;
|
|
||||||
// } // THIS IS NOW DONE IN init.js
|
|
||||||
|
|
||||||
// Update the installed version
|
// Update the installed version
|
||||||
if (settingsStore.getItem('PWAInstalled')) {
|
if (settingsStore.getItem('PWAInstalled')) {
|
||||||
params.PWAInstalled = params.appVersion;
|
params.PWAInstalled = params.appVersion;
|
||||||
|
@ -683,7 +683,6 @@ define(rqDef, function(util) {
|
|||||||
* @param {String} url An optional download URL
|
* @param {String} url An optional download URL
|
||||||
*/
|
*/
|
||||||
function showUpgradeReady(ver, type, url) {
|
function showUpgradeReady(ver, type, url) {
|
||||||
params.upgradeNeeded = true;
|
|
||||||
document.getElementById('alertBoxPersistent').innerHTML =
|
document.getElementById('alertBoxPersistent').innerHTML =
|
||||||
'<div id="upgradeAlert" class="alert alert-info alert-dismissible">\n' +
|
'<div id="upgradeAlert" class="alert alert-info alert-dismissible">\n' +
|
||||||
' <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>\n' +
|
' <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>\n' +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user