More consistent install prompt display for PWA

Former-commit-id: 7ed42494b6ccbffe0f2257c74c644e6f692ce544 [formerly 85ec8d4fdf382ad5e28936a29fdb62e640bd1dfe [formerly a5755452c18ba85b1ce0f9f85107760fb0637922]]
Former-commit-id: bd47fdf3f64498dd0a1f73dbe1ad218e443bf75c
Former-commit-id: e05712aa5c719079bc6e8a283b8cc2fb5274b902
This commit is contained in:
Jaifroid 2021-01-17 13:10:45 +00:00
parent d315e5a2fa
commit 0106b0e7b2
2 changed files with 13 additions and 6 deletions

View File

@ -770,8 +770,9 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
' <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>\n' +
' <span id="persistentMessage"></span>\n' +
'</div>\n';
document.getElementById('persistentMessage').innerHTML = 'Version ' + key.replace(/kiwix-precache-/, '') + ' is ready to install!'
+ ' (Re-launch app to install.)';
var loadOrInstall = params.PWAInstalled ? 'install' : 'load';
document.getElementById('persistentMessage').innerHTML = 'Version ' + key.replace(/kiwix-precache-/, '') + ' is ready to '
+ loadOrInstall + '! (Re-launch app to ' + loadOrInstall + '.)';
});
});
} else if (params.upgradeNeeded) {

View File

@ -201,9 +201,11 @@ window.addEventListener('beforeinstallprompt', function(e) {
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
// Show the install buttons
// Show the install button
divInstall2.style.display = 'block';
btnInstall2.addEventListener('click', installApp);
// Don't display prompt if the PWA for this version is already installed
if (!params.beforeinstallpromptFired && params.PWAInstalled !== params.version) {
if (!params.beforeinstallpromptFired) {
params.beforeinstallpromptFired = true;
btnInstall1.addEventListener('click', installApp);
btnLater.addEventListener('click', function (e) {
@ -214,8 +216,6 @@ window.addEventListener('beforeinstallprompt', function(e) {
}, 4000);
params.installLater = true;
});
divInstall2.style.display = 'block';
btnInstall2.addEventListener('click', installApp);
}
});
@ -239,6 +239,12 @@ function installApp(e) {
deferredPrompt = null;
params.beforeinstallpromptFired = false;
});
// The app hasn't actually been installed or use has uninstalled, so we need to reset any setting
if (params.storeType === 'cookie') {
document.cookie = 'PWAInstalled=; expires=Thu, 01 Jan 1970 00:00:00 GMT';
} else if (params.storeType === 'local_storage') {
localStorage.removeItem(params.keyPrefix + 'PWAInstalled');
}
}
window.addEventListener('appinstalled', function(e) {