From 5a131ccee3f0adcc29bb60a8155e87fffb82672f Mon Sep 17 00:00:00 2001 From: silas Date: Mon, 8 Oct 2018 15:05:58 +0200 Subject: [PATCH] Install-button verschwindet nach abbruch --- public/js/app.js | 32 +++++++++++++------ src/js/lib/pwa-assets.js | 23 ++++++++++--- .../js/Fragment/WordRotatorSettingFragment.js | 11 ++----- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 889c9e1..614a409 100755 --- a/public/js/app.js +++ b/public/js/app.js @@ -4606,11 +4606,26 @@ InitPromise.addPromise(function(app){ class InstallManager { static init() { window.addEventListener('beforeinstallprompt', e => { - this.deferredPromt = e; e.preventDefault(); - if (this.canInstallListener) { - this.canInstallListener(this.deferredPromt); - } + this.setDeferredPrompt(e); + }); + } + + static setDeferredPrompt(e){ + this.deferredPromt = e; + if (this.canInstallListener) { + this.canInstallListener(this.deferredPromt); + } + } + + static async prompt(){ + if (Helper.isNotNull(this.deferredPromt)){ + this.deferredPromt.prompt(); + return this.deferredPromt.userChoice(); + } + return Promise.resolve({ + "outcome":"dismissed", + "platform":"" }); } @@ -6796,14 +6811,11 @@ class WordRotatorSettingFragment extends LocalStorageSettingsFragment { this.getSite().startSite(PrivacyPolicySite); }); - InstallManager.setCanInstallListener((e) => { + InstallManager.setCanInstallListener(() => { let installButton = this.findBy("#install-button"); installButton.addEventListener("click", () => { - e.prompt(); - e["userChoice"].then(res => { - if (res["outcome"] === 'accepted') { - installButton.classList.add("hidden"); - } + InstallManager.prompt().then(() => { + installButton.classList.add("hidden"); }); }); installButton.classList.remove("hidden"); diff --git a/src/js/lib/pwa-assets.js b/src/js/lib/pwa-assets.js index 9f1b8f5..9cf9022 100755 --- a/src/js/lib/pwa-assets.js +++ b/src/js/lib/pwa-assets.js @@ -11,11 +11,26 @@ class DelayPromise extends Promise { class InstallManager { static init() { window.addEventListener('beforeinstallprompt', e => { - this.deferredPromt = e; e.preventDefault(); - if (this.canInstallListener) { - this.canInstallListener(this.deferredPromt); - } + this.setDeferredPrompt(e); + }); + } + + static setDeferredPrompt(e){ + this.deferredPromt = e; + if (this.canInstallListener) { + this.canInstallListener(this.deferredPromt); + } + } + + static async prompt(){ + if (Helper.isNotNull(this.deferredPromt)){ + this.deferredPromt.prompt(); + return this.deferredPromt.userChoice(); + } + return Promise.resolve({ + "outcome":"dismissed", + "platform":"" }); } diff --git a/src/module/Application/pwa/js/Fragment/WordRotatorSettingFragment.js b/src/module/Application/pwa/js/Fragment/WordRotatorSettingFragment.js index d015133..757cbd2 100644 --- a/src/module/Application/pwa/js/Fragment/WordRotatorSettingFragment.js +++ b/src/module/Application/pwa/js/Fragment/WordRotatorSettingFragment.js @@ -61,16 +61,11 @@ export class WordRotatorSettingFragment extends LocalStorageSettingsFragment { this.getSite().startSite(PrivacyPolicySite); }); - InstallManager.setCanInstallListener((e) => { - console.log("can install!"); + InstallManager.setCanInstallListener(() => { let installButton = this.findBy("#install-button"); installButton.addEventListener("click", () => { - e.prompt(); - e["userChoice"].then(res => { - console.log(res); - if (res["outcome"] === 'accepted') { - installButton.classList.add("hidden"); - } + InstallManager.prompt().then(() => { + installButton.classList.add("hidden"); }); }); installButton.classList.remove("hidden");