WebUI: clear timer variable properly

In JS the timer handle pool is reused and therefore require careful handling of it.
This commit is contained in:
Chocobo1 2024-07-26 04:58:21 +08:00
parent 7131d1bd6b
commit bf7e1516d5
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
7 changed files with 18 additions and 8 deletions

View file

@ -705,7 +705,7 @@ window.addEventListener("DOMContentLoaded", () => {
}; };
})(); })();
let syncMainDataTimeoutID; let syncMainDataTimeoutID = -1;
let syncRequestInProgress = false; let syncRequestInProgress = false;
const syncMainData = function() { const syncMainData = function() {
const url = new URI("api/v2/sync/maindata"); const url = new URI("api/v2/sync/maindata");
@ -889,6 +889,7 @@ window.addEventListener("DOMContentLoaded", () => {
return; return;
clearTimeout(syncMainDataTimeoutID); clearTimeout(syncMainDataTimeoutID);
syncMainDataTimeoutID = -1;
if (window.qBittorrent.Client.isStopped()) if (window.qBittorrent.Client.isStopped())
return; return;

View file

@ -306,6 +306,8 @@ window.qBittorrent.PropFiles ??= (() => {
return; return;
clearTimeout(loadTorrentFilesDataTimer); clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesDataTimer = -1;
new Request({ new Request({
url: "api/v2/torrents/filePrio", url: "api/v2/torrents/filePrio",
method: "post", method: "post",
@ -331,7 +333,7 @@ window.qBittorrent.PropFiles ??= (() => {
torrentFilesTable.updateTable(false); torrentFilesTable.updateTable(false);
}; };
let loadTorrentFilesDataTimer; let loadTorrentFilesDataTimer = -1;
const loadTorrentFilesData = function() { const loadTorrentFilesData = function() {
if ($("prop_files").hasClass("invisible") if ($("prop_files").hasClass("invisible")
|| $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) {
@ -378,6 +380,7 @@ window.qBittorrent.PropFiles ??= (() => {
const updateData = function() { const updateData = function() {
clearTimeout(loadTorrentFilesDataTimer); clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesDataTimer = -1;
loadTorrentFilesData(); loadTorrentFilesData();
}; };

View file

@ -72,7 +72,7 @@ window.qBittorrent.PropGeneral ??= (() => {
piecesBar.clear(); piecesBar.clear();
}; };
let loadTorrentDataTimer; let loadTorrentDataTimer = -1;
const loadTorrentData = function() { const loadTorrentData = function() {
if ($("prop_general").hasClass("invisible") if ($("prop_general").hasClass("invisible")
|| $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) {
@ -250,6 +250,7 @@ window.qBittorrent.PropGeneral ??= (() => {
const updateData = function() { const updateData = function() {
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = -1;
loadTorrentData(); loadTorrentData();
}; };

View file

@ -37,7 +37,7 @@ window.qBittorrent.PropPeers ??= (() => {
}; };
const torrentPeersTable = new window.qBittorrent.DynamicTable.TorrentPeersTable(); const torrentPeersTable = new window.qBittorrent.DynamicTable.TorrentPeersTable();
let loadTorrentPeersTimer; let loadTorrentPeersTimer = -1;
let syncTorrentPeersLastResponseId = 0; let syncTorrentPeersLastResponseId = 0;
let show_flags = true; let show_flags = true;
@ -109,6 +109,7 @@ window.qBittorrent.PropPeers ??= (() => {
const updateData = function() { const updateData = function() {
clearTimeout(loadTorrentPeersTimer); clearTimeout(loadTorrentPeersTimer);
loadTorrentPeersTimer = -1;
loadTorrentPeersData(); loadTorrentPeersData();
}; };

View file

@ -39,7 +39,7 @@ window.qBittorrent.PropTrackers ??= (() => {
let current_hash = ""; let current_hash = "";
const torrentTrackersTable = new window.qBittorrent.DynamicTable.TorrentTrackersTable(); const torrentTrackersTable = new window.qBittorrent.DynamicTable.TorrentTrackersTable();
let loadTrackersDataTimer; let loadTrackersDataTimer = -1;
const loadTrackersData = function() { const loadTrackersData = function() {
if ($("prop_trackers").hasClass("invisible") if ($("prop_trackers").hasClass("invisible")
@ -119,6 +119,7 @@ window.qBittorrent.PropTrackers ??= (() => {
const updateData = function() { const updateData = function() {
clearTimeout(loadTrackersDataTimer); clearTimeout(loadTrackersDataTimer);
loadTrackersDataTimer = -1;
loadTrackersData(); loadTrackersData();
}; };

View file

@ -88,7 +88,7 @@ window.qBittorrent.PropWebseeds ??= (() => {
let current_hash = ""; let current_hash = "";
let loadWebSeedsDataTimer; let loadWebSeedsDataTimer = -1;
const loadWebSeedsData = function() { const loadWebSeedsData = function() {
if ($("prop_webseeds").hasClass("invisible") if ($("prop_webseeds").hasClass("invisible")
|| $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) {
@ -138,6 +138,7 @@ window.qBittorrent.PropWebseeds ??= (() => {
const updateData = function() { const updateData = function() {
clearTimeout(loadWebSeedsDataTimer); clearTimeout(loadWebSeedsDataTimer);
loadWebSeedsDataTimer = -1;
loadWebSeedsData(); loadWebSeedsData();
}; };

View file

@ -47,7 +47,7 @@ window.qBittorrent.Search ??= (() => {
}; };
const searchTabIdPrefix = "Search-"; const searchTabIdPrefix = "Search-";
let loadSearchPluginsTimer; let loadSearchPluginsTimer = -1;
const searchPlugins = []; const searchPlugins = [];
let prevSearchPluginsResponse; let prevSearchPluginsResponse;
let selectedCategory = "QBT_TR(All categories)QBT_TR[CONTEXT=SearchEngineWidget]"; let selectedCategory = "QBT_TR(All categories)QBT_TR[CONTEXT=SearchEngineWidget]";
@ -207,7 +207,7 @@ window.qBittorrent.Search ??= (() => {
rowId: 0, rowId: 0,
selectedRowIds: [], selectedRowIds: [],
running: true, running: true,
loadResultsTimer: null, loadResultsTimer: -1,
sort: { column: searchResultsTable.sortedColumn, reverse: searchResultsTable.reverseSort }, sort: { column: searchResultsTable.sortedColumn, reverse: searchResultsTable.reverseSort },
}); });
updateSearchResultsData(searchId); updateSearchResultsData(searchId);
@ -507,6 +507,7 @@ window.qBittorrent.Search ??= (() => {
}, },
onClose: function() { onClose: function() {
clearTimeout(loadSearchPluginsTimer); clearTimeout(loadSearchPluginsTimer);
loadSearchPluginsTimer = -1;
} }
}); });
} }
@ -569,6 +570,7 @@ window.qBittorrent.Search ??= (() => {
if (state) { if (state) {
state.running = false; state.running = false;
clearTimeout(state.loadResultsTimer); clearTimeout(state.loadResultsTimer);
state.loadResultsTimer = -1;
} }
}; };