Fix service worker scope in BrowserNotificatator (#5391)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2024-04-18 01:11:52 +07:00
committed by GitHub
parent a29e1701be
commit e16172086c
2 changed files with 19 additions and 8 deletions
@@ -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) {
+18 -7
View File
@@ -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<boolean> {
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