Files
binome/src/utils/notification.ts
Julien Calixte 8887cdbf88 chore: upgrade tooling stack
- TypeScript 3.9 -> 5.8
- ESLint 6 -> 9 (flat config)
- Prettier 1 -> 3
- eslint-plugin-vue 6 -> 9
- Add vue-tsc for type checking
- Migrate Sass @import to @use syntax
- Fix Pinia persistence config for v4
- Add Spotify type declarations
- Remove unused registerServiceWorker.ts
2026-01-24 21:36:43 +01:00

48 lines
1.0 KiB
TypeScript

type ShowNotification = (
title: string,
options?: NotificationOptions
) => Promise<void>
let showNotification: ShowNotification | null = null
export const setNotificationInstance = (sn: ShowNotification) => {
showNotification = sn
}
export const notify: ShowNotification = async (title, options?) => {
const showCustomNotification = async () => {
if (!showNotification) {
return
}
await showNotification(title, {
icon: '/img/icons/apple-touch-icon.png',
badge: '/img/badge.png',
tag: 'binome',
renotify: true,
silent: true,
...options
} as NotificationOptions)
}
try {
if (!('Notification' in window)) {
return
}
if (Notification.permission === 'granted') {
showCustomNotification()
return
}
if (Notification.permission !== 'denied') {
const permission = await Notification.requestPermission()
if (permission === 'granted') {
showCustomNotification()
}
}
} catch (error) {
return
}
}