parent
db5315d7e4
commit
61401c8a14
@ -1,8 +1,5 @@
|
|||||||
console.log('[SW] Push worker started')
|
console.log('[SW] Push worker started')
|
||||||
|
|
||||||
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1
|
|
||||||
var userInvisibleSupported = isFirefox ? true : false
|
|
||||||
|
|
||||||
var pendingNotification = false
|
var pendingNotification = false
|
||||||
|
|
||||||
var defaultBaseUrl
|
var defaultBaseUrl
|
||||||
@ -31,7 +28,7 @@ self.addEventListener('push', function(event) {
|
|||||||
Promise.all([getMuteUntil(), getLastAliveTime()]).then(function (result) {
|
Promise.all([getMuteUntil(), getLastAliveTime()]).then(function (result) {
|
||||||
var muteUntil = result[0]
|
var muteUntil = result[0]
|
||||||
var lastAliveTime = result[1]
|
var lastAliveTime = result[1]
|
||||||
if (userInvisibleSupported &&
|
if (userInvisibleIsSupported() &&
|
||||||
muteUntil &&
|
muteUntil &&
|
||||||
nowTime < muteUntil) {
|
nowTime < muteUntil) {
|
||||||
console.log('Supress notification because mute for ', Math.ceil((muteUntil - nowTime) / 60000), 'min')
|
console.log('Supress notification because mute for ', Math.ceil((muteUntil - nowTime) / 60000), 'min')
|
||||||
@ -61,7 +58,7 @@ self.addEventListener('push', function(event) {
|
|||||||
|
|
||||||
var closePromise = notificationPromise.catch(function () {
|
var closePromise = notificationPromise.catch(function () {
|
||||||
console.log('[SW] Closing all notifications on push', hasActiveWindows)
|
console.log('[SW] Closing all notifications on push', hasActiveWindows)
|
||||||
if (userInvisibleSupported) {
|
if (userInvisibleIsSupported()) {
|
||||||
return closeAllNotifications()
|
return closeAllNotifications()
|
||||||
}
|
}
|
||||||
var promise = self.registration.showNotification('Telegram').then(function () {
|
var promise = self.registration.showNotification('Telegram').then(function () {
|
||||||
@ -221,7 +218,7 @@ self.addEventListener('notificationclick', function(event) {
|
|||||||
notification.close()
|
notification.close()
|
||||||
|
|
||||||
var action = event.action
|
var action = event.action
|
||||||
if (action == 'mute1d' && userInvisibleSupported) {
|
if (action == 'mute1d' && userInvisibleIsSupported()) {
|
||||||
console.log('[SW] mute for 1d')
|
console.log('[SW] mute for 1d')
|
||||||
muteUntil = +(new Date()) + 86400000
|
muteUntil = +(new Date()) + 86400000
|
||||||
IDBManager.setItem('push_mute_until', muteUntil)
|
IDBManager.setItem('push_mute_until', muteUntil)
|
||||||
@ -438,3 +435,8 @@ function getSettings() {
|
|||||||
return {}
|
return {}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function userInvisibleIsSupported() {
|
||||||
|
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1
|
||||||
|
return isFirefox ? true : false
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user