🐛 (notification) fix notification
This commit is contained in:
@@ -1,19 +1,46 @@
|
||||
declare const Notification: any
|
||||
|
||||
export const notify = (message: string) => {
|
||||
let showNotification:
|
||||
| ((
|
||||
title: string,
|
||||
options?: NotificationOptions | undefined
|
||||
) => Promise<void>)
|
||||
| null = null
|
||||
|
||||
export const setNotificationInstance = (
|
||||
sn: (
|
||||
title: string,
|
||||
options?: NotificationOptions | undefined
|
||||
) => Promise<void>
|
||||
) => {
|
||||
showNotification = sn
|
||||
}
|
||||
|
||||
export const notify = (
|
||||
title: string,
|
||||
options?: NotificationOptions | undefined
|
||||
) => {
|
||||
try {
|
||||
console.log(showNotification)
|
||||
|
||||
if (!showNotification) {
|
||||
return
|
||||
}
|
||||
if (!('Notification' in window)) {
|
||||
return
|
||||
} else if (Notification.permission === 'granted') {
|
||||
new Notification(message)
|
||||
showNotification(title, options)
|
||||
} else if (Notification.permission !== 'denied') {
|
||||
Notification.requestPermission((permission: any) => {
|
||||
if (!showNotification) {
|
||||
return
|
||||
}
|
||||
if (!('permission' in Notification)) {
|
||||
Notification.permission = permission
|
||||
}
|
||||
|
||||
if (permission === 'granted') {
|
||||
new Notification(message)
|
||||
showNotification(title, options)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user