mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
15 lines
614 B
TypeScript
15 lines
614 B
TypeScript
/// <reference types="@types/serviceworker" />
|
|
/* global clients */
|
|
// eslint-disable-next-line no-restricted-globals
|
|
addEventListener('notificationclick', (event) => {
|
|
console.log('On notification click: ', event.notification.tag);
|
|
event.notification.close();
|
|
if (!event.notification.tag.startsWith('message-')) return;
|
|
event.waitUntil(clients.matchAll({ type: 'window' }).then((clientList) => {
|
|
for (const client of clientList) {
|
|
if (client.url === '/home/messages' && 'focus' in client) return client.focus();
|
|
}
|
|
if (clients.openWindow) clients.openWindow('/home/messages');
|
|
}));
|
|
});
|