-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.js
31 lines (27 loc) · 1013 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
let deferredInstallPrompt = null;
const installButton = document.getElementById('butInstall');
function saveBeforeInstallPromptEvent(evt) {
deferredInstallPrompt = evt;
installButton.removeAttribute('hidden');
}
function installPWA(evt) {
deferredInstallPrompt.prompt();
evt.srcElement.setAttribute('hidden', true);
deferredInstallPrompt.userChoice.then((choice) => {
if (choice.outcome === 'accepted') {
// eslint-disable-next-line no-console
console.log(`User accepted the A2HS prompt ${choice}`);
} else {
// eslint-disable-next-line no-console
console.log(`User dismissed the A2HS prompt ${choice}`);
}
deferredInstallPrompt = null;
});
}
function logAppInstalled(evt) {
// eslint-disable-next-line no-console
console.log(`Camic App was installed. ${evt}`);
}
installButton.addEventListener('click', installPWA);
window.addEventListener('beforeinstallprompt', saveBeforeInstallPromptEvent);
window.addEventListener('appinstalled', logAppInstalled);