From 396b651fc5cc019ba7c3958e5c4a11ad6d099438 Mon Sep 17 00:00:00 2001 From: silas Date: Sat, 6 Oct 2018 18:25:57 +0200 Subject: [PATCH] Installierbar und Settings bearbeitet --- public/html/application/credits.html | 2 +- public/index.html | 2 +- public/js/app.js | 25 +++++++++++-------- src/js/lib/pwa-assets.js | 18 ++++++------- .../pwa/html/application/credits.html | 4 ++- .../js/Fragment/WordRotatorSettingFragment.js | 7 +++++- 6 files changed, 33 insertions(+), 25 deletions(-) diff --git a/public/html/application/credits.html b/public/html/application/credits.html index 281c686..c25c9ce 100644 --- a/public/html/application/credits.html +++ b/public/html/application/credits.html @@ -1 +1 @@ -
\ No newline at end of file +

\ No newline at end of file diff --git a/public/index.html b/public/index.html index 90f85f5..d9014f8 100755 --- a/public/index.html +++ b/public/index.html @@ -30,7 +30,7 @@ - + diff --git a/public/js/app.js b/public/js/app.js index 489d4e0..889c9e1 100755 --- a/public/js/app.js +++ b/public/js/app.js @@ -4603,30 +4603,28 @@ InitPromise.addPromise(function(app){ app.addDeepLink("newPassword", SetNewPasswordSite); }); -class InstallManager{ - static init(){ - console.log("init"); +class InstallManager { + static init() { window.addEventListener('beforeinstallprompt', e => { - console.log("beforeinstallprompt", e); this.deferredPromt = e; - if (this.canInstallListener){ + e.preventDefault(); + if (this.canInstallListener) { this.canInstallListener(this.deferredPromt); } }); } - static setCanInstallListener(listener, callIfCanInstall){ + + static setCanInstallListener(listener, callIfCanInstall) { this.canInstallListener = listener; callIfCanInstall = Helper.nonNull(callIfCanInstall, true); - if (callIfCanInstall && Helper.nonNull(this.deferredPromt)){ + if (callIfCanInstall && Helper.nonNull(this.deferredPromt)) { this.canInstallListener(this.deferredPromt); } } } + InstallManager.init(); -window.addEventListener("load", () => { - console.log("loaded"); -}); class Matomo { @@ -6799,9 +6797,14 @@ class WordRotatorSettingFragment extends LocalStorageSettingsFragment { }); InstallManager.setCanInstallListener((e) => { - let installButton =this.findBy("#install-button"); + let installButton = this.findBy("#install-button"); installButton.addEventListener("click", () => { e.prompt(); + e["userChoice"].then(res => { + if (res["outcome"] === 'accepted') { + 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 a216076..9f1b8f5 100755 --- a/src/js/lib/pwa-assets.js +++ b/src/js/lib/pwa-assets.js @@ -8,30 +8,28 @@ class DelayPromise extends Promise { } } -class InstallManager{ - static init(){ - console.log("init"); +class InstallManager { + static init() { window.addEventListener('beforeinstallprompt', e => { - console.log("beforeinstallprompt", e); this.deferredPromt = e; - if (this.canInstallListener){ + e.preventDefault(); + if (this.canInstallListener) { this.canInstallListener(this.deferredPromt); } }); } - static setCanInstallListener(listener, callIfCanInstall){ + + static setCanInstallListener(listener, callIfCanInstall) { this.canInstallListener = listener; callIfCanInstall = Helper.nonNull(callIfCanInstall, true); - if (callIfCanInstall && Helper.nonNull(this.deferredPromt)){ + if (callIfCanInstall && Helper.nonNull(this.deferredPromt)) { this.canInstallListener(this.deferredPromt); } } } + InstallManager.init(); -window.addEventListener("load", () => { - console.log("loaded"); -}); class Matomo { diff --git a/src/module/Application/pwa/html/application/credits.html b/src/module/Application/pwa/html/application/credits.html index 281c686..618508f 100644 --- a/src/module/Application/pwa/html/application/credits.html +++ b/src/module/Application/pwa/html/application/credits.html @@ -1 +1,3 @@ -
\ No newline at end of file +
+

+
\ No newline at end of file diff --git a/src/module/Application/pwa/js/Fragment/WordRotatorSettingFragment.js b/src/module/Application/pwa/js/Fragment/WordRotatorSettingFragment.js index 3559f99..58b9704 100644 --- a/src/module/Application/pwa/js/Fragment/WordRotatorSettingFragment.js +++ b/src/module/Application/pwa/js/Fragment/WordRotatorSettingFragment.js @@ -62,9 +62,14 @@ export class WordRotatorSettingFragment extends LocalStorageSettingsFragment { }); InstallManager.setCanInstallListener((e) => { - let installButton =this.findBy("#install-button"); + let installButton = this.findBy("#install-button"); installButton.addEventListener("click", () => { e.prompt(); + e["userChoice"].then(res => { + if (res["outcome"] === 'accepted') { + installButton.classList.add("hidden"); + } + }); }); installButton.classList.remove("hidden"); });