Add notification permission request
This commit is contained in:
parent
251a616fa4
commit
9ae499f18c
@ -9,10 +9,30 @@ export function parseLocation(location?: string | undefined) {
|
||||
}
|
||||
|
||||
export function notify(msg: string): void {
|
||||
// Let's check if the browser supports notifications
|
||||
if (!('Notification' in window)) {
|
||||
alert('This browser does not support desktop notification');
|
||||
}
|
||||
|
||||
// Let's check whether notification permissions have already been granted
|
||||
else if (Notification.permission === 'granted') {
|
||||
// If it's okay let's create a notification
|
||||
const n = new Notification(msg);
|
||||
setTimeout(() => n && n.close(), 4000);
|
||||
}
|
||||
|
||||
// Otherwise, we need to ask the user for permission
|
||||
else if (Notification.permission !== 'denied') {
|
||||
Notification.requestPermission().then(function (permission) {
|
||||
// If the user accepts, let's create a notification
|
||||
if (permission === 'granted') {
|
||||
const n = new Notification(msg);
|
||||
setTimeout(() => n && n.close(), 4000);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function markPage(text: string, version: string) {
|
||||
jQuery('body').append(
|
||||
'<div style="' +
|
||||
|
Loading…
Reference in New Issue
Block a user