Customize install prompt behavior

This commit is contained in:
RobinLinus 2019-03-14 20:05:25 +01:00
parent b788898134
commit ef77ffb534
2 changed files with 21 additions and 0 deletions

View file

@ -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));
});
}
}
});
}