diff --git a/WebContent/js/cah.app.js b/WebContent/js/cah.app.js index 1bd1e39..5d1716c 100644 --- a/WebContent/js/cah.app.js +++ b/WebContent/js/cah.app.js @@ -65,6 +65,17 @@ $(document).ready(function() { app_resize(); }); +$(window).focus(function() { + cah.windowActive = true; + if (cah.missedGameListRefresh) { + cah.GameList.instance.update(); + } +}); + +$(window).blur(function() { + cah.windowActive = false; +}); + /** * Handle a key up event in the nick box. If the key was enter, try to register with the server. * diff --git a/WebContent/js/cah.gamelist.js b/WebContent/js/cah.gamelist.js index b7b7bbc..0b6e913 100644 --- a/WebContent/js/cah.gamelist.js +++ b/WebContent/js/cah.gamelist.js @@ -80,9 +80,12 @@ cah.GameList.prototype.hide = function() { * Query the server to update the game list. */ cah.GameList.prototype.update = function() { - if ($(this.element_).is(":visible")) { + if ($(this.element_).is(":visible") && cah.windowActive) { // TODO display a loading indicator of some sort cah.Ajax.build(cah.$.AjaxOperation.GAME_LIST).run(); + cah.missedGameListRefresh = false; + } else { + cah.missedGameListRefresh = true; } }; diff --git a/WebContent/js/cah.js b/WebContent/js/cah.js index d716472..4ffe4d7 100644 --- a/WebContent/js/cah.js +++ b/WebContent/js/cah.js @@ -57,6 +57,21 @@ cah.ignoreList = {}; */ cah.hideConnectQuit = false; +/** + * Whether the game's browser window has focus, so we don't update the game list when we're not + * active. + * + * @type {Boolean} + */ +cah.windowActive = true; + +/** + * Whether we've missed a game list refresh due to not being the active window. + * + * @type {Boolean} + */ +cah.missedGameListRefresh = false; + /** * Binds a function to a "this object". Result is a new function that will do the right thing across * contexts.