open url by send message to page
Deploy frontend / frontend (push) Successful in 1m3s

This commit is contained in:
2024-12-02 19:08:39 +02:00
parent de8496395b
commit 7b5cfebe80
2 changed files with 28 additions and 21 deletions
+26 -19
View File
@@ -104,31 +104,39 @@ self.addEventListener('notificationclick', (event) => {
console.log('focus') console.log('focus')
return Promise.all([ return Promise.all([
client.focus(),
client.postMessage({ client.postMessage({
type: 'notificationClick', type: 'notificationClick',
tag: event.notification.tag, tag: event.notification.tag,
payload: event.notification.payload, payload: event.notification.payload,
matchUrl: true, matchUrl: true,
}), }),
client.focus(),
]) ])
} }
} }
return Promise.resolve() if (clients.openWindow) {
.then(() => { console.log('open new window', urlToOpen)
if (!clients.openWindow) {
throw new Error('clients.openWindow not available') return clients.openWindow(urlToOpen).then((client) => {
} if (!client) {
return clients.openWindow(urlToOpen).then((newClient) => { console.log('new window not opened')
if (!newClient) { for (const client of clientList) {
throw new Error('new window not opened') client.postMessage({
} type: 'notificationClick',
}) url: urlToOpen,
}) tag: event.notification.tag,
.catch((error) => { payload: event.notification.payload,
console.debug('Error', error) matchUrl: false,
msg: 'new window not opened',
})
break
}
}
})
} else {
console.log('clients.openWindow not available')
for (const client of clientList) { for (const client of clientList) {
return Promise.all([
client.postMessage({ client.postMessage({
type: 'notificationClick', type: 'notificationClick',
url: urlToOpen, url: urlToOpen,
@@ -136,11 +144,10 @@ self.addEventListener('notificationclick', (event) => {
payload: event.notification.payload, payload: event.notification.payload,
matchUrl: false, matchUrl: false,
msg: 'clients.openWindow not available', msg: 'clients.openWindow not available',
}),
client.focus(),
])
}
}) })
break
}
}
}) })
.catch((error) => { .catch((error) => {
+1 -1
View File
@@ -65,7 +65,7 @@ app.use(PrimeVue, {
app.mount('#app') app.mount('#app')
registerServiceWorker() registerServiceWorker()
.then((registration) => { .then(() => {
console.log('Service Worker успешно зарегистрирован') console.log('Service Worker успешно зарегистрирован')
navigator.serviceWorker.addEventListener('message', (event) => { navigator.serviceWorker.addEventListener('message', (event) => {
console.debug('serviceWorker message', event.data) console.debug('serviceWorker message', event.data)