From ec2937ec1f3b0ae153f79604eb35b57ffe0f9af2 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 13 Nov 2023 17:29:25 +0200 Subject: add options for marking single notification as read --- .../desktop_notification_utils.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/services/desktop_notification_utils/desktop_notification_utils.js') diff --git a/src/services/desktop_notification_utils/desktop_notification_utils.js b/src/services/desktop_notification_utils/desktop_notification_utils.js index eb58f39b..dbca4173 100644 --- a/src/services/desktop_notification_utils/desktop_notification_utils.js +++ b/src/services/desktop_notification_utils/desktop_notification_utils.js @@ -1,4 +1,8 @@ -import { showDesktopNotification as swDesktopNotification, isSWSupported } from '../sw/sw.js' +import { + showDesktopNotification as swDesktopNotification, + closeDesktopNotification as swCloseDesktopNotification, + isSWSupported +} from '../sw/sw.js' const state = { failCreateNotif: false } export const showDesktopNotification = (rootState, desktopNotificationOpts) => { @@ -16,3 +20,19 @@ export const showDesktopNotification = (rootState, desktopNotificationOpts) => { } } } + +export const closeDesktopNotification = (rootState, id) => { + if (!('Notification' in window && window.Notification.permission === 'granted')) return + + if (isSWSupported()) { + swCloseDesktopNotification({ id }) + } +} + +export const closeAllDesktopNotifications = (rootState) => { + if (!('Notification' in window && window.Notification.permission === 'granted')) return + + if (isSWSupported()) { + swCloseDesktopNotification() + } +} -- cgit v1.2.3-70-g09d2