aboutsummaryrefslogtreecommitdiff
path: root/src/services/desktop_notification_utils/desktop_notification_utils.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2023-10-26 15:42:21 +0300
committerHenry Jameson <me@hjkos.com>2023-10-26 15:42:21 +0300
commit0628aac664be4ccce361d319fad201c44d9257fe (patch)
treebd59c87ca770b9da97bef6e589064a03f0ddc01b /src/services/desktop_notification_utils/desktop_notification_utils.js
parent1b7e930b2e850408f46876395a85628b05729cc9 (diff)
fallback to old notification method, don't spam if old way of creating
notification fails, try to use favicon
Diffstat (limited to 'src/services/desktop_notification_utils/desktop_notification_utils.js')
-rw-r--r--src/services/desktop_notification_utils/desktop_notification_utils.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/services/desktop_notification_utils/desktop_notification_utils.js b/src/services/desktop_notification_utils/desktop_notification_utils.js
index c31a1030..eb58f39b 100644
--- a/src/services/desktop_notification_utils/desktop_notification_utils.js
+++ b/src/services/desktop_notification_utils/desktop_notification_utils.js
@@ -1,8 +1,18 @@
-import { showDesktopNotification as swDesktopNotification } from '../sw/sw.js'
+import { showDesktopNotification as swDesktopNotification, isSWSupported } from '../sw/sw.js'
+const state = { failCreateNotif: false }
export const showDesktopNotification = (rootState, desktopNotificationOpts) => {
if (!('Notification' in window && window.Notification.permission === 'granted')) return
if (rootState.statuses.notifications.desktopNotificationSilence) { return }
- swDesktopNotification(desktopNotificationOpts)
+ if (isSWSupported()) {
+ swDesktopNotification(desktopNotificationOpts)
+ } else if (!state.failCreateNotif) {
+ try {
+ const desktopNotification = new window.Notification(desktopNotificationOpts.title, desktopNotificationOpts)
+ setTimeout(desktopNotification.close.bind(desktopNotification), 5000)
+ } catch {
+ state.failCreateNotif = true
+ }
+ }
}