update sw
Deploy app frontend / app frontend (push) Successful in 1m29s

This commit is contained in:
2024-12-05 11:04:04 +02:00
parent 9c0ce14013
commit ddcda323a1
6 changed files with 217 additions and 192 deletions
@@ -61,6 +61,8 @@ import { isNotFoundError } from '@/api/PouchDB'
import { saveUserChatSettings } from '@/api/userChatSettings'
import { getQrCodeDocument } from '@/api/qrCode'
const debug: (...data: unknown[]) => void = inject('debug')!
// Проверки iOS и запуска из главного экрана
const isIOS = computed(
() => /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window && window.MSStream),
@@ -99,7 +101,7 @@ async function requestNotificationPermission() {
const subscription = await registration.pushManager
.subscribe(await subscribeOptionsPromise)
.catch(async (error) => {
console.debug('subscribe error', error)
debug('subscribe error', error)
const oldSubscription = await registration.pushManager.getSubscription()
if (!oldSubscription) {
throw error
@@ -119,26 +121,23 @@ const getPushSubscription = async () => {
const permission = await registration.pushManager.permissionState(
await subscribeOptionsPromise,
)
console.debug('permission', permission)
if (permission === 'prompt') {
return
}
if (permission !== 'granted') {
debug('permission', permission)
if (permission === 'denied') {
throw new Error(`Разрешение на уведомления не предоставлено: ${permission}`)
}
const subscription = await registration.pushManager.getSubscription()
if (subscription) {
console.debug('Уже есть активная подписка:', subscription)
debug('Уже есть активная подписка:', subscription)
return subscription
} else {
console.debug('Нет активной подписки на Push-уведомления.')
debug('Нет активной подписки на Push-уведомления.')
}
} else {
console.warn('Push уведомления или Service Worker не поддерживаются в этом браузере.')
debug('Push уведомления или Service Worker не поддерживаются в этом браузере.')
}
} catch (error) {
console.error('Произошла ошибка при получении подписки:', error)
debug('Произошла ошибка при получении подписки:', error)
throw error
}
}
@@ -151,7 +150,7 @@ const stage = ref<'receivePushSubscription' | 'createPushSubscription' | 'remove
const { isPending, isError, error, mutate } = useMutation({
mutationKey: [stage],
mutationFn: async () => {
console.debug('stage', stage.value)
debug({ stage: stage.value })
try {
if (stage.value === 'receivePushSubscription') {
const chatSettingsDocument = await getUserChatSettingsDocument({
@@ -160,13 +159,16 @@ const { isPending, isError, error, mutate } = useMutation({
user_chat_role,
}).catch((error) => {
if (!isNotFoundError(error)) {
console.debug('chatSettingsDocument error not found - its ok', error)
debug('chatSettingsDocument error', error)
throw error
}
console.debug('chatSettingsDocument error', error)
debug('chatSettingsDocument not found') // it's ok
})
if (chatSettingsDocument) {
console.debug('chatSettingsDocument', chatSettingsDocument)
debug(
'chatSettingsDocument.is_push_notification_enabled',
chatSettingsDocument.is_push_notification_enabled,
)
}
if (
(chatSettingsDocument && chatSettingsDocument.is_push_notification_enabled) ||
@@ -186,9 +188,11 @@ const { isPending, isError, error, mutate } = useMutation({
}
enabled.value = true
stage.value = 'removePushSubscription'
debug('subscribed')
} else {
stage.value = 'createPushSubscription'
enabled.value = false
debug('have to createPushSubscription')
}
} else {
stage.value = 'createPushSubscription'
@@ -211,7 +215,7 @@ const { isPending, isError, error, mutate } = useMutation({
}
} catch (error) {
enabled.value = false
console.debug('unknown error at stage ', stage.value, error)
debug('unknown error at stage ', stage.value, error)
throw error
}
return null