2020-07-03 19:47:30 +03:00
|
|
|
import { Options, Permission } from './types/notification'
|
2020-06-27 18:20:00 +03:00
|
|
|
import { promisified } from './tauri'
|
|
|
|
|
|
|
|
async function isPermissionGranted(): Promise<boolean | null> {
|
|
|
|
if (window.Notification.permission !== 'default') {
|
|
|
|
return await Promise.resolve(window.Notification.permission === 'granted')
|
|
|
|
}
|
|
|
|
return await promisified({
|
|
|
|
cmd: 'isNotificationPermissionGranted'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function requestPermission(): Promise<Permission> {
|
2020-07-03 19:47:30 +03:00
|
|
|
return await window.Notification.requestPermission()
|
2020-06-27 18:20:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function sendNotification(options: Options | string): void {
|
2020-07-03 19:47:30 +03:00
|
|
|
if (typeof options === 'string') {
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new window.Notification(options)
|
|
|
|
} else {
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new window.Notification(options.title, options)
|
2020-06-27 18:20:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendNotification,
|
2020-07-03 19:47:30 +03:00
|
|
|
requestPermission,
|
2020-06-27 18:20:00 +03:00
|
|
|
isPermissionGranted
|
|
|
|
}
|