Add notification permission request
This commit is contained in:
		| @@ -9,8 +9,28 @@ export function parseLocation(location?: string | undefined) { | |||||||
| } | } | ||||||
|  |  | ||||||
| export function notify(msg: string): void { | 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); |         const n = new Notification(msg); | ||||||
|         setTimeout(() => n && n.close(), 4000); |         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) { | export function markPage(text: string, version: string) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user