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.
This commit is contained in:
bolshoytoster 2025-06-05 11:28:35 +01:00 committed by GitHub
commit 617b1da842
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
});
};