|
|
@ -21,32 +21,28 @@ self.addEventListener('push', function(event) { |
|
|
|
|
|
|
|
|
|
|
|
var hasActiveWindows = false |
|
|
|
var hasActiveWindows = false |
|
|
|
var checksPromise = new Promise(function (resolve, reject) { |
|
|
|
var checksPromise = new Promise(function (resolve, reject) { |
|
|
|
if (!obj.badge) { |
|
|
|
|
|
|
|
return reject() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var nowTime = +(new Date()) |
|
|
|
var nowTime = +(new Date()) |
|
|
|
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] |
|
|
|
|
|
|
|
return clients.matchAll({type: 'window'}).then(function(clientList) { |
|
|
|
|
|
|
|
console.log('matched clients', clientList) |
|
|
|
|
|
|
|
hasActiveWindows = clientList.length > 0 |
|
|
|
|
|
|
|
if (hasActiveWindows) { |
|
|
|
|
|
|
|
console.log('Supress notification because some instance is alive') |
|
|
|
|
|
|
|
return reject() |
|
|
|
|
|
|
|
} |
|
|
|
if (userInvisibleIsSupported() && |
|
|
|
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') |
|
|
|
return reject() |
|
|
|
return reject() |
|
|
|
} |
|
|
|
} |
|
|
|
if (lastAliveTime && |
|
|
|
if (!obj.badge) { |
|
|
|
nowTime - lastAliveTime < 60000) { |
|
|
|
|
|
|
|
return clients.matchAll({type: 'window'}).then(function(clientList) { |
|
|
|
|
|
|
|
console.log('matched clients', clientList) |
|
|
|
|
|
|
|
hasActiveWindows = clientList.length > 0 |
|
|
|
|
|
|
|
if (hasActiveWindows) { |
|
|
|
|
|
|
|
console.log('Supress notification because some instance is alive') |
|
|
|
|
|
|
|
return reject() |
|
|
|
return reject() |
|
|
|
} |
|
|
|
} |
|
|
|
return resolve() |
|
|
|
return resolve() |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
return resolve() |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|