diff --git a/app/js/lib/push_worker.js b/app/js/lib/push_worker.js index 21f622dc..e0c5a454 100644 --- a/app/js/lib/push_worker.js +++ b/app/js/lib/push_worker.js @@ -22,6 +22,7 @@ self.addEventListener('push', function(event) { var obj = event.data.json() console.log('[SW] push', obj) + var hasActiveWindows = false var checksPromise = new Promise(function (resolve, reject) { if (!obj.badge) { return reject() @@ -40,7 +41,8 @@ self.addEventListener('push', function(event) { nowTime - lastAliveTime < 60000) { return clients.matchAll({type: 'window'}).then(function(clientList) { console.log('matched clients', clientList) - if (clientList.length) { + hasActiveWindows = clientList.length > 0 + if (hasActiveWindows) { console.log('Supress notification because some instance is alive') return reject() } @@ -59,7 +61,7 @@ self.addEventListener('push', function(event) { var closePromise = notificationPromise.catch(function () { console.log('[SW] Closing all notifications on push') - if (userInvisibleSupported) { + if (userInvisibleSupported || hasActiveWindows) { return closeAllNotifications() } var promise = self.registration.showNotification('Telegram').then(function () {