forked from FoundKeyGang/FoundKey
service worker: also show notifications if client is connected
This commit is contained in:
parent
a1f3b212fe
commit
c34bebdf46
1 changed files with 2 additions and 8 deletions
|
@ -24,19 +24,13 @@ self.addEventListener('activate', ev => {
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('push', ev => {
|
self.addEventListener('push', ev => {
|
||||||
// クライアント取得
|
ev.waitUntil((async <K extends keyof pushNotificationDataMap>() => {
|
||||||
ev.waitUntil(self.clients.matchAll({
|
|
||||||
includeUncontrolled: true,
|
|
||||||
type: 'window'
|
|
||||||
}).then(async <K extends keyof pushNotificationDataMap>(clients: readonly WindowClient[]) => {
|
|
||||||
const data: pushNotificationDataMap[K] = ev.data?.json();
|
const data: pushNotificationDataMap[K] = ev.data?.json();
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
// case 'driveFileCreated':
|
// case 'driveFileCreated':
|
||||||
case 'notification':
|
case 'notification':
|
||||||
case 'unreadMessagingMessage':
|
case 'unreadMessagingMessage':
|
||||||
// クライアントがあったらストリームに接続しているということなので通知しない
|
|
||||||
if (clients.length != 0) return;
|
|
||||||
return createNotification(data);
|
return createNotification(data);
|
||||||
case 'readAllNotifications':
|
case 'readAllNotifications':
|
||||||
for (const n of await self.registration.getNotifications()) {
|
for (const n of await self.registration.getNotifications()) {
|
||||||
|
@ -67,7 +61,7 @@ self.addEventListener('push', ev => {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}));
|
})());
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('notificationclick', <K extends keyof pushNotificationDataMap>(ev: ServiceWorkerGlobalScopeEventMap['notificationclick']) => {
|
self.addEventListener('notificationclick', <K extends keyof pushNotificationDataMap>(ev: ServiceWorkerGlobalScopeEventMap['notificationclick']) => {
|
||||||
|
|
Loading…
Reference in a new issue