service worker: also show notifications if client is connected

This commit is contained in:
Johann150 2022-11-12 18:23:18 +01:00
parent 0c3c855d29
commit db0e6a241c
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -24,19 +24,13 @@ self.addEventListener('activate', ev => {
});
self.addEventListener('push', ev => {
// クライアント取得
ev.waitUntil(self.clients.matchAll({
includeUncontrolled: true,
type: 'window'
}).then(async <K extends keyof pushNotificationDataMap>(clients: readonly WindowClient[]) => {
ev.waitUntil((async <K extends keyof pushNotificationDataMap>() => {
const data: pushNotificationDataMap[K] = ev.data?.json();
switch (data.type) {
// case 'driveFileCreated':
case 'notification':
case 'unreadMessagingMessage':
// クライアントがあったらストリームに接続しているということなので通知しない
if (clients.length != 0) return;
return createNotification(data);
case 'readAllNotifications':
for (const n of await self.registration.getNotifications()) {
@ -69,7 +63,7 @@ self.addEventListener('push', ev => {
}
return createEmptyNotification();
}));
})());
});
self.addEventListener('notificationclick', <K extends keyof pushNotificationDataMap>(ev: ServiceWorkerGlobalScopeEventMap['notificationclick']) => {