From ef77ffb5347b111a88fd0bf0ffa0c10d3aea77c6 Mon Sep 17 00:00:00 2001 From: RobinLinus Date: Thu, 14 Mar 2019 20:05:25 +0100 Subject: [PATCH] Customize install prompt behavior --- client/index.html | 10 ++++++++++ client/scripts/ui.js | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/client/index.html b/client/index.html index c5942b0..8920347 100644 --- a/client/index.html +++ b/client/index.html @@ -44,6 +44,11 @@ + @@ -173,6 +178,11 @@ + + + + + diff --git a/client/scripts/ui.js b/client/scripts/ui.js index 970660b..7639ea1 100644 --- a/client/scripts/ui.js +++ b/client/scripts/ui.js @@ -527,6 +527,17 @@ if ('serviceWorker' in navigator) { window.addEventListener('beforeinstallprompt', e => { if (window.matchMedia('(display-mode: standalone)').matches) { return event.preventDefault(); + } else { + const deferredPrompt = e; + const btn = document.querySelector('#install') + btn.hidden = false; + btn.onclick = _ => { + deferredPrompt.prompt(); + // Wait for the user to respond to the prompt + deferredPrompt.userChoice.then((resp) => { + console.log(JSON.stringify(resp)); + }); + } } }); }