♻️ (bp)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user