WebUI: keep client session from expiring

This commit is contained in:
bolshoytoster 2025-05-31 20:46:11 +01:00
commit 851defd937

View file

@ -73,7 +73,11 @@ window.qBittorrent.Client ??= (() => {
}; };
const getSyncMainDataInterval = () => { const getSyncMainDataInterval = () => {
return customSyncMainDataInterval ? customSyncMainDataInterval : serverSyncMainDataInterval; return document.hidden
? window.qBittorrent.Cache.preferences.get().web_ui_session_timeout * 500
: customSyncMainDataInterval
? customSyncMainDataInterval
: serverSyncMainDataInterval;
}; };
let stopped = false; let stopped = false;
@ -779,8 +783,6 @@ window.addEventListener("DOMContentLoaded", (event) => {
let syncMainDataTimeoutID = -1; let syncMainDataTimeoutID = -1;
let syncRequestInProgress = false; let syncRequestInProgress = false;
const syncMainData = () => { const syncMainData = () => {
if (document.hidden)
return;
syncRequestInProgress = true; syncRequestInProgress = true;
const url = new URL("api/v2/sync/maindata", window.location); const url = new URL("api/v2/sync/maindata", window.location);
url.search = new URLSearchParams({ url.search = new URLSearchParams({
@ -956,6 +958,10 @@ window.addEventListener("DOMContentLoaded", (event) => {
if (fullUpdate) if (fullUpdate)
// re-select previously selected rows // re-select previously selected rows
torrentsTable.reselectRows(torrentsTableSelectedRows); torrentsTable.reselectRows(torrentsTableSelectedRows);
} else if (response.status == 403) {
const errorDiv = document.getElementById("error_div");
if (errorDiv)
errorDiv.textContent = "QBT_TR(You've been logged out)QBT_TR[CONTEXT=HttpServer]";
} }
syncRequestInProgress = false; syncRequestInProgress = false;
@ -966,7 +972,11 @@ window.addEventListener("DOMContentLoaded", (event) => {
if (errorDiv) if (errorDiv)
errorDiv.textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]"; errorDiv.textContent = "QBT_TR(qBittorrent client is not reachable)QBT_TR[CONTEXT=HttpServer]";
syncRequestInProgress = false; syncRequestInProgress = false;
syncData(2000); syncData(
document.hidden
? window.qBittorrent.Cache.preferences.get().web_ui_session_timeout * 500
: 2000
);
}); });
}; };