From: Benjamin Auder Date: Sat, 13 Nov 2021 15:05:38 +0000 (+0100) Subject: Use document.hidden instead of document.hasFocus() X-Git-Url: https://git.auder.net/variants/Chakart/css/doc/html/img/index.css?a=commitdiff_plain;h=016306e3aa2262e141899f8d4b900421d68f5439;p=xogo.git Use document.hidden instead of document.hasFocus() --- diff --git a/app.js b/app.js index 56ba25a..8bd5e70 100644 --- a/app.js +++ b/app.js @@ -253,7 +253,7 @@ const messageCenter = (msg) => { switch (obj.code) { // Start new game: case "gamestart": { - if (!$.hasFocus()) notifyMe("game"); + if (document.hidden) notifyMe("game"); gid = obj.gid; initializeGame(obj); break; @@ -285,7 +285,7 @@ const messageCenter = (msg) => { break; // Receive opponent's move: case "newmove": - if (!$.hasFocus()) notifyMe("move"); + if (document.hidden) notifyMe("move"); vr.playReceivedMove(obj.moves, () => { if (vr.getCurrentScore(obj.moves[obj.moves.length-1]) != "*") { localStorage.removeItem("gid"); @@ -360,7 +360,7 @@ function notifyMe(code) { } if (Notification.permission === 'granted') doNotify(); else if (Notification.permission !== 'denied') { - Notification.requestPermission().then((permission) => { + Notification.requestPermission().then(permission => { if (permission === 'granted') doNotify(); }); } diff --git a/base_rules.js b/base_rules.js index ff698f4..acee324 100644 --- a/base_rules.js +++ b/base_rules.js @@ -2090,9 +2090,9 @@ export default class ChessRules { else launchAnimation(); //focused user! }; let boardContainer = document.getElementById("boardContainer"); - if (!document.hasFocus()) { - window.onfocus = () => { - window.onfocus = undefined; + if (document.hidden) { + document.onvisibilitychange = () => { + document.onvisibilitychange = undefined; checkDisplayThenAnimate(); }; }