-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
42 lines (35 loc) · 1.33 KB
/
script.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
33
34
35
36
37
38
39
40
41
42
//rgister service worker
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("service-worker.js").then(registration => {
console.log("Service worker registered")
console.log(registration);
}).catch(error => {
console.log("Service worker error")
console.log(error);
})
}
else {
alert("Service worker not working")
}
// Initialize deferredPrompt for use later to show browser install prompt.
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;
// Optionally, send analytics event that PWA install promo was shown.
//console.log(`'beforeinstallprompt' event was fired.`);
});
//show install dialog
const install = document.getElementById('install')
install.addEventListener('click', async () => {
// Show the install prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
const { outcome } = await deferredPrompt.userChoice;
// Optionally, send analytics event with outcome of user choice
// console.log(`User response to the install prompt: ${outcome}`);
// We've used the prompt, and can't use it again, throw it away
deferredPrompt = null;
});