From 6f3715426a95bd3ffdf19137e990d75b9f6b7196 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 11 Aug 2017 11:44:21 +0200 Subject: [PATCH] Fixed excessive polling behavior --- .../js/WoltLabSuite/Core/Notification/Handler.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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; }, /** -- 2.20.1