diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index 91d6f4695..09d43f9b5 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -73,6 +73,9 @@ window.qBittorrent.Client ??= (() => { }; const getSyncMainDataInterval = () => { + // Sync at half of the session timeout (in ms), to prevent timing out + if (document.hidden) + return (window.qBittorrent.Cache.preferences.get().web_ui_session_timeout * 1000) / 2; return customSyncMainDataInterval ? customSyncMainDataInterval : serverSyncMainDataInterval; }; @@ -779,8 +782,6 @@ window.addEventListener("DOMContentLoaded", (event) => { let syncMainDataTimeoutID = -1; let syncRequestInProgress = false; const syncMainData = () => { - if (document.hidden) - return; syncRequestInProgress = true; const url = new URL("api/v2/sync/maindata", window.location); url.search = new URLSearchParams({ @@ -966,7 +967,9 @@ window.addEventListener("DOMContentLoaded", (event) => { if (errorDiv) errorDiv.textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]"; syncRequestInProgress = false; - syncData(2000); + syncData(document.hidden + ? (window.qBittorrent.Cache.preferences.get().web_ui_session_timeout * 1000) / 2 + : 2000); }); };