send notification when page is focused

Previous code was somewhat bugged
This commit is contained in:
creeper123123321 2021-04-04 08:14:50 -03:00 committed by GitHub
parent f799856df1
commit dbcce81922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,13 +32,6 @@ var listening = document.getElementById("listening");
var actions = document.getElementById("actions"); var actions = document.getElementById("actions");
var accounts = document.getElementById("accounts-list"); var accounts = document.getElementById("accounts-list");
var listenVisible = false; var listenVisible = false;
var pageBlur = false;
document.addEventListener("focus", () => {
pageBlur = false;
});
document.addEventListener("blur", () => {
pageBlur = true;
});
// Util // Util
isMojang = it => !!it.clientToken; isMojang = it => !!it.clientToken;
@ -319,7 +312,7 @@ function handleSWMsg(event) {
callback(data.action); callback(data.action);
} }
function authNotification(msg, yes, no) { function authNotification(msg, yes, no) {
if (!navigator.serviceWorker || (!pageBlur && !document.hidden) || Notification.permission != "granted") { if (!navigator.serviceWorker || Notification.permission != "granted") {
if (confirm(msg)) yes(); else no(); if (confirm(msg)) yes(); else no();
return; return;
} }