diff --git a/plugins/notification-resources/src/components/BrowserNotificatator.svelte b/plugins/notification-resources/src/components/BrowserNotificatator.svelte index 85b92b246c..a2379e35f2 100644 --- a/plugins/notification-resources/src/components/BrowserNotificatator.svelte +++ b/plugins/notification-resources/src/components/BrowserNotificatator.svelte @@ -28,7 +28,7 @@ try { const loc = getCurrentLocation() const registration = await navigator.serviceWorker.register('/serviceWorker.js', { - scope: `./${loc.path[0]}/${loc.path[1]}` + scope: `${loc.path[0]}/${loc.path[1]}` }) const current = await registration.pushManager.getSubscription() if (current == null) { diff --git a/plugins/notification-resources/src/utils.ts b/plugins/notification-resources/src/utils.ts index 589161f6e6..49a9ca02c6 100644 --- a/plugins/notification-resources/src/utils.ts +++ b/plugins/notification-resources/src/utils.ts @@ -41,7 +41,14 @@ import notification, { type MentionInboxNotification } from '@hcengineering/notification' import { MessageBox, getClient } from '@hcengineering/presentation' -import { getLocation, navigate, showPopup, type Location, type ResolvedLocation } from '@hcengineering/ui' +import { + getCurrentLocation, + getLocation, + navigate, + showPopup, + type Location, + type ResolvedLocation +} from '@hcengineering/ui' import { get } from 'svelte/store' import { InboxNotificationsClientImpl } from './inboxNotificationsClient' @@ -535,12 +542,16 @@ export function openInboxDoc ( export async function checkPermission (value: boolean): Promise { if (!value) return true - if ('Notification' in window) { - if (Notification?.permission === 'denied') return false - if (Notification?.permission === 'granted') return true - if (Notification?.permission === 'default') { - const res = await Notification?.requestPermission() - return res === 'granted' + if ('serviceWorker' in navigator && 'PushManager' in window) { + try { + const loc = getCurrentLocation() + const registration = await navigator.serviceWorker.getRegistration(`/${loc.path[0]}/${loc.path[1]}`) + if (registration !== undefined) { + const current = await registration.pushManager.getSubscription() + return current !== null + } + } catch { + return false } } return false