Add notification permission request

This commit is contained in:
Anton Vakhrushev 2020-10-18 10:47:09 +03:00
parent 251a616fa4
commit 9ae499f18c

View File

@ -9,8 +9,28 @@ 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) {