Add logic for checking installed version

Former-commit-id: e1b6e37af929fc9fbb2d6608d6532939fac6ce41 [formerly ceaf7091f8e2d8e94cbd8e7d725962b3a148f68e]
Former-commit-id: d77eca66500e9441c2d1bf9ba13706802a4d4fbf
This commit is contained in:
Jaifroid 2020-01-22 00:20:41 +00:00
parent 63eaa00374
commit 08765f0401

View File

@ -79,6 +79,7 @@ params['allowInternetAccess'] = params['allowInternetAccess'] || false; //Do not
params['printIntercept'] = false; params['printIntercept'] = false;
params['printInterception'] = false; params['printInterception'] = false;
params['appIsLaunching'] = true; //Allows some routines to tell if the app has just been launched params['appIsLaunching'] = true; //Allows some routines to tell if the app has just been launched
params['PWAInstalled'] = getCookie('PWAInstalled');
//Prevent app boot loop with problematic pages that cause an app crash //Prevent app boot loop with problematic pages that cause an app crash
if (getCookie('lastPageLoad') == 'failed') { if (getCookie('lastPageLoad') == 'failed') {
@ -183,6 +184,8 @@ window.addEventListener('beforeinstallprompt', function(e) {
console.log('beforeinstallprompt fired'); console.log('beforeinstallprompt fired');
// Prevent Chrome 76 and earlier from automatically showing a prompt // Prevent Chrome 76 and earlier from automatically showing a prompt
e.preventDefault(); e.preventDefault();
// Don't display prompt if the PWA for this version is already installed
if (params.PWAInstalled === params.version) return;
// Stash the event so it can be triggered later. // Stash the event so it can be triggered later.
deferredPrompt = e; deferredPrompt = e;
// Show the install button // Show the install button
@ -215,6 +218,11 @@ function installApp(e) {
}); });
} }
window.addEventListener('appinstalled', function(e) {
params.PWAInstalled = params.version;
document.cookie = 'PWAInstalled=' + params.PWAInstalled + ';expires=Fri, 31 Dec 9999 23:59:59 GMT';
});
function getCookie(name) { function getCookie(name) {
var result; var result;
if (params.cookieSupport == 'cookie') { if (params.cookieSupport == 'cookie') {