mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 19:11:33 +03:00
Fix service worker scope in BrowserNotificatator (#5391)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
a29e1701be
commit
e16172086c
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user