Browse Source

improved timeout for hiding push

master
Igor Zhukov 8 years ago
parent
commit
7d68cc1da7
  1. 8
      app/js/lib/push_worker.js
  2. 2
      app/service_worker.js

8
app/js/lib/push_worker.js

@ -28,8 +28,10 @@ self.addEventListener('push', function(event) {
var closeAll = obj.badge ? !fireNotification(obj, event) : true var closeAll = obj.badge ? !fireNotification(obj, event) : true
if (closeAll) { if (closeAll) {
console.log('[SW] Closing all notifications on push')
var promise = self.registration.showNotification('Telegram').then(function () { var promise = self.registration.showNotification('Telegram').then(function () {
return closeAllNotifications(obj) // return closeAllNotifications()
setTimeout(closeAllNotifications, 100)
}).catch(function (error) { }).catch(function (error) {
console.error('Show notification error', error) console.error('Show notification error', error)
}) })
@ -65,7 +67,7 @@ self.addEventListener('message', function(event) {
} }
} }
if (event.data.type == 'notifications_clear') { if (event.data.type == 'notifications_clear') {
closeAllNotifications(event.data) closeAllNotifications()
} }
if (event.data.baseUrl) { if (event.data.baseUrl) {
baseUrl = event.data.baseUrl baseUrl = event.data.baseUrl
@ -160,7 +162,7 @@ function removeFromNotifications(notification) {
} }
} }
function closeAllNotifications(obj) { function closeAllNotifications() {
for (var i = 0, len = notifications.length; i < len; i++) { for (var i = 0, len = notifications.length; i < len; i++) {
try { try {
notifications[i].close() notifications[i].close()

2
app/service_worker.js

@ -1,3 +1,3 @@
importScripts('js/lib/push_worker.js') importScripts('js/lib/push_worker.js')
// Version 49 // Version 50
Loading…
Cancel
Save