2025-06-09 10:00:55 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { isBrowserNotificationsEnabled, showBrowserNotification } from '../lib/client/browserNotifications'
|
2025-06-14 18:56:58 +00:00
|
|
|
import {
|
|
|
|
|
makeBrowserNotificationOptions,
|
|
|
|
|
makeBrowserNotificationTitle,
|
|
|
|
|
} from '../lib/client/notificationOptions'
|
2025-06-09 10:00:55 +00:00
|
|
|
|
2025-06-10 17:42:42 +00:00
|
|
|
document.addEventListener('sse:new-notification', (event) => {
|
2025-06-09 10:00:55 +00:00
|
|
|
if (isBrowserNotificationsEnabled()) {
|
|
|
|
|
const payload = event.detail
|
|
|
|
|
const notification = showBrowserNotification(
|
2025-06-14 18:56:58 +00:00
|
|
|
makeBrowserNotificationTitle(payload.title),
|
|
|
|
|
makeBrowserNotificationOptions(payload, { removeActions: true })
|
2025-06-09 10:00:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Handle notification click
|
|
|
|
|
if (notification) {
|
|
|
|
|
notification.onclick = () => {
|
|
|
|
|
const defaultAction = payload.actions.find((a) => a.url) ?? payload.actions[0]
|
|
|
|
|
if (defaultAction?.url) {
|
|
|
|
|
window.open(defaultAction.url, '_blank')
|
|
|
|
|
}
|
|
|
|
|
notification.close()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
</script>
|