♻️ (bp)

This commit is contained in:
2020-07-04 22:24:58 +02:00
parent 48030ff848
commit 59c48184a7
3 changed files with 24 additions and 25 deletions

View File

@@ -1,5 +1,3 @@
declare const Notification: any
type ShowNotification = (
title: string,
options?: NotificationOptions
@@ -11,7 +9,10 @@ export const setNotificationInstance = (sn: ShowNotification) => {
showNotification = sn
}
export const notify = (title: string, options?: NotificationOptions) => {
export const notify: ShowNotification = async (
title: string,
options?: NotificationOptions
) => {
const showCustomNotification = (
title: string,
options?: NotificationOptions
@@ -31,18 +32,19 @@ export const notify = (title: string, options?: NotificationOptions) => {
try {
if (!('Notification' in window)) {
return
} else if (Notification.permission === 'granted') {
showCustomNotification(title, options)
} else if (Notification.permission !== 'denied') {
Notification.requestPermission((permission: any) => {
if (!('permission' in Notification)) {
Notification.permission = permission
}
}
if (permission === 'granted') {
showCustomNotification(title, options)
}
})
if (Notification.permission === 'granted') {
showCustomNotification(title, options)
return
}
if (Notification.permission !== 'denied') {
const permission = await Notification.requestPermission()
if (permission === 'granted') {
showCustomNotification(title, options)
}
}
} catch (error) {
return