test shit
This commit is contained in:
parent
38daf98559
commit
a2daac6dd2
2 changed files with 2 additions and 19 deletions
|
@ -28,7 +28,7 @@ function subscribePush (registration, isEnabled, vapidPublicKey) {
|
|||
if (!vapidPublicKey) return Promise.reject(new Error('VAPID public key is not found'))
|
||||
|
||||
const subscribeOptions = {
|
||||
userVisibleOnly: false,
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: urlBase64ToUint8Array(vapidPublicKey)
|
||||
}
|
||||
return registration.pushManager.subscribe(subscribeOptions)
|
||||
|
|
19
src/sw.js
19
src/sw.js
|
@ -59,24 +59,7 @@ const setSettings = async () => {
|
|||
}
|
||||
|
||||
const showPushNotification = async (event) => {
|
||||
const activeClients = await getWindowClients()
|
||||
await setSettings()
|
||||
// Only show push notifications if all tabs/windows are closed
|
||||
if (activeClients.length === 0) {
|
||||
const data = event.data.json()
|
||||
|
||||
const url = `${self.registration.scope}api/v1/notifications/${data.notification_id}`
|
||||
const notification = await fetch(url, { headers: { Authorization: 'Bearer ' + data.access_token } })
|
||||
const notificationJson = await notification.json()
|
||||
const parsedNotification = parseNotification(notificationJson)
|
||||
|
||||
const res = prepareNotificationObject(parsedNotification, i18n)
|
||||
|
||||
if (state.allowedNotificationTypes.has(parsedNotification.type)) {
|
||||
return self.registration.showNotification(res.title, res)
|
||||
}
|
||||
}
|
||||
return Promise.resolve()
|
||||
return self.registration.showNotification(res.title, res)
|
||||
}
|
||||
|
||||
self.addEventListener('push', async (event) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue