From: Alexander Ebert Date: Fri, 11 Aug 2017 09:44:21 +0000 (+0200) Subject: Fixed excessive polling behavior X-Git-Tag: 3.1.0_Alpha_1~44 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6f3715426a95bd3ffdf19137e990d75b9f6b7196;p=GitHub%2FWoltLab%2FWCF.git Fixed excessive polling behavior --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/Handler.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/Handler.js index b600007dc3..46b33b4599 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/Handler.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/Handler.js @@ -49,7 +49,7 @@ define(['Ajax', 'Core', 'EventHandler'], function(Ajax, Core, EventHandler) { document.addEventListener('visibilitychange', this._onVisibilityChange.bind(this)); window.addEventListener('storage', this._onStorage.bind(this)); - this._onVisibilityChange(); + this._onVisibilityChange(null); if (options.enableNotifications) { switch (window.Notification.permission) { @@ -70,19 +70,20 @@ define(['Ajax', 'Core', 'EventHandler'], function(Ajax, Core, EventHandler) { /** * Detects when this window is hidden or restored. * + * @param {Event} event * @protected */ - _onVisibilityChange: function() { - _inactiveSince = (document.hidden) ? Date.now() : 0; - + _onVisibilityChange: function(event) { // document was hidden before - if (!document.hidden) { + if (event !== null && !document.hidden) { var difference = (Date.now() - _inactiveSince) / 60000; if (difference > 4) { this._resetTimer(); this._dispatchRequest(); } } + + _inactiveSince = (document.hidden) ? Date.now() : 0; }, /**