From 016306e3aa2262e141899f8d4b900421d68f5439 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Sat, 13 Nov 2021 16:05:38 +0100
Subject: [PATCH] Use document.hidden instead of document.hasFocus()

---
 app.js        | 6 +++---
 base_rules.js | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

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();
       };
     }
-- 
2.44.0