Browse Source

No new notification if has active window

master
Igor Zhukov 8 years ago
parent
commit
edbdba582e
  1. 6
      app/js/lib/push_worker.js

6
app/js/lib/push_worker.js

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

Loading…
Cancel
Save