No new notification if has active window

This commit is contained in:
Igor Zhukov 2016-12-20 19:09:47 +03:00
parent 82786e91ce
commit edbdba582e

View File

@ -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 () {