From 617b1da842527bc806f8bcdeaaf76a431f5a6405 Mon Sep 17 00:00:00 2001 From: bolshoytoster <91278344+bolshoytoster@users.noreply.github.com> Date: Thu, 5 Jun 2025 11:28:35 +0100 Subject: [PATCH] WebUI: Keep client session from expiring when the page is hidden In #22567, I made it so the web UI wouldn't refresh the main data while the page is hidden. This causes the session to time out (after 1 hour by default). This PR changes that to instead refresh every Preferences/WebUI/SessionTimeout / 2 instead of not at all, which should keep the session alive. PR #22804. --- src/webui/www/private/scripts/client.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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); }); };