From d8292b7601b9f3e314da0d4139c76cf9a8e92d43 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 3 Dec 2022 01:47:35 +0200 Subject: [PATCH] try different approach to opening push notification --- files/assets/js/service_worker.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/files/assets/js/service_worker.js b/files/assets/js/service_worker.js index 4d6f9e29b..8aac6de88 100644 --- a/files/assets/js/service_worker.js +++ b/files/assets/js/service_worker.js @@ -70,7 +70,9 @@ self.addEventListener('push', function(event) { }); self.addEventListener('notificationclick', (e) => { - if (e.notification.data.url) - e.waitUntil(clients.openWindow(e.notification.data.url)); e.notification.close(); -}); + e.waitUntil(clients.matchAll({ type: 'window' }).then((clientsArr) => { + const hadWindowToFocus = clientsArr.some((windowClient) => windowClient.url === e.notification.data.url ? (windowClient.focus(), true) : false); + if (!hadWindowToFocus) clients.openWindow(e.notification.data.url).then((windowClient) => windowClient ? windowClient.focus() : null); + })); +});