-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnotification.js
34 lines (31 loc) · 1.05 KB
/
notification.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
export function sendNotif(message) {
if (!("Notification" in window)) {
// Check if the browser supports notifications
console.error('Browser do not supprt notification')
} else if (Notification.permission === "granted") {
// Check whether notification permissions have already been granted;
// if so, create a notification
console.log('sending notification')
const notification = new Notification(message);
// …
}
console.log(Notification.permission)
}
export function accesPush() {
if (!("Notification" in window)) {
console.error('Browser do not supprt notification')
return false
} else if (Notification.permission === "granted") {
return true;
} else if (Notification.permission === "denied") {
return false
}else if (Notification.permission !== "denied") {
Notification.requestPermission().then((permission) => {
// If the user accepts, let's create a notification
if (permission === "granted") {
console.log('Granted')
}
});
return 'W1'
}
}