-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
33 lines (28 loc) · 995 Bytes
/
install.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const buttonInstall = document.querySelector('.installer')
let deferredPrompt;
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent the mini-infobar from appearing on mobile
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
// Update UI notify the user they can install the PWA
//showInstallPromotion();
});
buttonInstall.addEventListener('click', (e) => {
// Hide the app provided install promotion
// hideMyInstallPromotion();
// Show the install prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the install prompt');
} else {
console.log('User dismissed the install prompt');
}
});
});
window.addEventListener('appinstalled', (evt) => {
// Log install to analytics
console.log('INSTALL: Success');
});