From 08765f0401c5fe95ffbaae667dfd758959b027cb Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Wed, 22 Jan 2020 00:20:41 +0000 Subject: [PATCH] Add logic for checking installed version Former-commit-id: e1b6e37af929fc9fbb2d6608d6532939fac6ce41 [formerly ceaf7091f8e2d8e94cbd8e7d725962b3a148f68e] Former-commit-id: d77eca66500e9441c2d1bf9ba13706802a4d4fbf --- www/js/init.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/www/js/init.js b/www/js/init.js index 9f20db88..be6c0d63 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -79,6 +79,7 @@ params['allowInternetAccess'] = params['allowInternetAccess'] || false; //Do not params['printIntercept'] = false; params['printInterception'] = false; 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 if (getCookie('lastPageLoad') == 'failed') { @@ -183,6 +184,8 @@ window.addEventListener('beforeinstallprompt', function(e) { console.log('beforeinstallprompt fired'); // Prevent Chrome 76 and earlier from automatically showing a prompt 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. deferredPrompt = e; // 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) { var result; if (params.cookieSupport == 'cookie') {