-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-script.js
67 lines (54 loc) · 1.73 KB
/
app-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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var content = document.getElementById("content");
var button = document.getElementById("continue-button");
var subButton = document.getElementById("Button_Image");
var addToHome = document.getElementById("addToHome");
//resgister service worker
if ("serviceWorker" in navigator) {
window.addEventListener("load", function() {
navigator.serviceWorker.register("./sw.js").then(
function(registration) {
// Registration was successful
console.log(
"ServiceWorker registration successful with scope: ",
registration.scope
);
},
function(err) {
// registration failed :(
console.log("ServiceWorker registration failed: ", err);
}
);
});
}
/* prompt user to add to their home screen */
let promptEvt;
window.addEventListener("beforeinstallprompt", evt => {
evt.preventDefault();
console.log("beforeinstallprompt:fired with :" + evt.returnValue);
//save event for future use
promptEvt = evt;
// Update UI notify the user they can add to home screen
return false;
});
function checkInstalledState() {
console.log("subButton clicked ");
//show install banner now
if (promptEvt !== undefined) {
// hide our user interface that shows our A2HS button
promptEvt.prompt();
promptEvt.userChoice.then(choiceResult => {
if (choiceResult.outcome === "accepted") {
console.log("User accepted the A2HS prompt");
} else {
console.log("User dismissed the A2HS prompt");
}
promptEvt = null;
});
}
}
subButton.addEventListener("click", checkInstalledState);
window.addEventListener("appinstalled", evt => {
console.log("a2hs installed :" + evt);
});
//notifications
var n = new Notification("Title", {});