Files
binome/src/utils/notification.ts

51 lines
1.1 KiB
TypeScript

declare const Notification: any
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') {
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') {
showNotification(title, options)
}
})
}
} catch (error) {
return
}
}