iOS sw
Deploy frontend / frontend (push) Successful in 57s

This commit is contained in:
2024-12-03 00:57:27 +02:00
parent 82b41e50a0
commit c567db944a
+33 -5
View File
@@ -8,6 +8,8 @@ self.addEventListener('install', (event) => {
// of event.waitUntil(); // of event.waitUntil();
}) })
const isIOS = /iPhone|iPad|iPod/i.test(navigator.userAgent)
self.addEventListener('activate', (event) => { self.addEventListener('activate', (event) => {
event.waitUntil( event.waitUntil(
clients.claim(), // Привязка нового сервис-воркера к текущим клиентам clients.claim(), // Привязка нового сервис-воркера к текущим клиентам
@@ -114,26 +116,52 @@ self.addEventListener('notificationclick', (event) => {
type: 'notificationClick', type: 'notificationClick',
tag: event.notification.tag, tag: event.notification.tag,
payload: event.notification.payload, payload: event.notification.payload,
url: urlToOpen,
matchUrl: true, matchUrl: true,
isIOS,
}), }),
]) ])
} }
} }
if (isIOS && clientList.length > 0) {
const client = clientList[0]
return Promise.all([
client.focus(),
client.postMessage({
type: 'notificationClick',
tag: event.notification.tag,
payload: event.notification.payload,
url: urlToOpen,
matchUrl: false,
isIOS,
}),
])
}
if (clients.openWindow) { if (clients.openWindow) {
console.log('open new window', urlToOpen) console.log('open new window', urlToOpen)
return clients.openWindow(urlToOpen).then((client) => { return clients.openWindow(urlToOpen).then((client) => {
if (!client) { if (client) {
return client.postMessage({
type: 'notificationClick',
tag: event.notification.tag,
payload: event.notification.payload,
url: urlToOpen,
matchUrl: true,
isIOS,
})
} else {
console.log('new window not opened') console.log('new window not opened')
for (const client of clientList) { for (const client of clientList) {
return client.postMessage({ return client.postMessage({
type: 'notificationClick', type: 'notificationClick',
url: urlToOpen,
tag: event.notification.tag, tag: event.notification.tag,
payload: event.notification.payload, payload: event.notification.payload,
url: urlToOpen,
matchUrl: false, matchUrl: false,
msg: 'new window not opened', isIOS,
}) })
} }
} }
@@ -144,11 +172,11 @@ self.addEventListener('notificationclick', (event) => {
for (const client of clientList) { for (const client of clientList) {
return client.postMessage({ return client.postMessage({
type: 'notificationClick', type: 'notificationClick',
url: urlToOpen,
tag: event.notification.tag, tag: event.notification.tag,
payload: event.notification.payload, payload: event.notification.payload,
url: urlToOpen,
matchUrl: false, matchUrl: false,
msg: 'clients.openWindow not available', isIOS,
}) })
} }
} }