From bf7e1516d57638774c2668e25523180045831227 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 26 Jul 2024 04:58:21 +0800 Subject: [PATCH] WebUI: clear timer variable properly In JS the timer handle pool is reused and therefore require careful handling of it. --- src/webui/www/private/scripts/client.js | 3 ++- src/webui/www/private/scripts/prop-files.js | 5 ++++- src/webui/www/private/scripts/prop-general.js | 3 ++- src/webui/www/private/scripts/prop-peers.js | 3 ++- src/webui/www/private/scripts/prop-trackers.js | 3 ++- src/webui/www/private/scripts/prop-webseeds.js | 3 ++- src/webui/www/private/scripts/search.js | 6 ++++-- 7 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index e578606f6..548550819 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -705,7 +705,7 @@ window.addEventListener("DOMContentLoaded", () => { }; })(); - let syncMainDataTimeoutID; + let syncMainDataTimeoutID = -1; let syncRequestInProgress = false; const syncMainData = function() { const url = new URI("api/v2/sync/maindata"); @@ -889,6 +889,7 @@ window.addEventListener("DOMContentLoaded", () => { return; clearTimeout(syncMainDataTimeoutID); + syncMainDataTimeoutID = -1; if (window.qBittorrent.Client.isStopped()) return; diff --git a/src/webui/www/private/scripts/prop-files.js b/src/webui/www/private/scripts/prop-files.js index 2e0d74dec..f396f0545 100644 --- a/src/webui/www/private/scripts/prop-files.js +++ b/src/webui/www/private/scripts/prop-files.js @@ -306,6 +306,8 @@ window.qBittorrent.PropFiles ??= (() => { return; clearTimeout(loadTorrentFilesDataTimer); + loadTorrentFilesDataTimer = -1; + new Request({ url: "api/v2/torrents/filePrio", method: "post", @@ -331,7 +333,7 @@ window.qBittorrent.PropFiles ??= (() => { torrentFilesTable.updateTable(false); }; - let loadTorrentFilesDataTimer; + let loadTorrentFilesDataTimer = -1; const loadTorrentFilesData = function() { if ($("prop_files").hasClass("invisible") || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { @@ -378,6 +380,7 @@ window.qBittorrent.PropFiles ??= (() => { const updateData = function() { clearTimeout(loadTorrentFilesDataTimer); + loadTorrentFilesDataTimer = -1; loadTorrentFilesData(); }; diff --git a/src/webui/www/private/scripts/prop-general.js b/src/webui/www/private/scripts/prop-general.js index 342e85fa0..2ef547f4f 100644 --- a/src/webui/www/private/scripts/prop-general.js +++ b/src/webui/www/private/scripts/prop-general.js @@ -72,7 +72,7 @@ window.qBittorrent.PropGeneral ??= (() => { piecesBar.clear(); }; - let loadTorrentDataTimer; + let loadTorrentDataTimer = -1; const loadTorrentData = function() { if ($("prop_general").hasClass("invisible") || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { @@ -250,6 +250,7 @@ window.qBittorrent.PropGeneral ??= (() => { const updateData = function() { clearTimeout(loadTorrentDataTimer); + loadTorrentDataTimer = -1; loadTorrentData(); }; diff --git a/src/webui/www/private/scripts/prop-peers.js b/src/webui/www/private/scripts/prop-peers.js index bb12d7449..aed2ea9a8 100644 --- a/src/webui/www/private/scripts/prop-peers.js +++ b/src/webui/www/private/scripts/prop-peers.js @@ -37,7 +37,7 @@ window.qBittorrent.PropPeers ??= (() => { }; const torrentPeersTable = new window.qBittorrent.DynamicTable.TorrentPeersTable(); - let loadTorrentPeersTimer; + let loadTorrentPeersTimer = -1; let syncTorrentPeersLastResponseId = 0; let show_flags = true; @@ -109,6 +109,7 @@ window.qBittorrent.PropPeers ??= (() => { const updateData = function() { clearTimeout(loadTorrentPeersTimer); + loadTorrentPeersTimer = -1; loadTorrentPeersData(); }; diff --git a/src/webui/www/private/scripts/prop-trackers.js b/src/webui/www/private/scripts/prop-trackers.js index f675075b0..c88cae879 100644 --- a/src/webui/www/private/scripts/prop-trackers.js +++ b/src/webui/www/private/scripts/prop-trackers.js @@ -39,7 +39,7 @@ window.qBittorrent.PropTrackers ??= (() => { let current_hash = ""; const torrentTrackersTable = new window.qBittorrent.DynamicTable.TorrentTrackersTable(); - let loadTrackersDataTimer; + let loadTrackersDataTimer = -1; const loadTrackersData = function() { if ($("prop_trackers").hasClass("invisible") @@ -119,6 +119,7 @@ window.qBittorrent.PropTrackers ??= (() => { const updateData = function() { clearTimeout(loadTrackersDataTimer); + loadTrackersDataTimer = -1; loadTrackersData(); }; diff --git a/src/webui/www/private/scripts/prop-webseeds.js b/src/webui/www/private/scripts/prop-webseeds.js index 0bbc90a25..5c0d4e64d 100644 --- a/src/webui/www/private/scripts/prop-webseeds.js +++ b/src/webui/www/private/scripts/prop-webseeds.js @@ -88,7 +88,7 @@ window.qBittorrent.PropWebseeds ??= (() => { let current_hash = ""; - let loadWebSeedsDataTimer; + let loadWebSeedsDataTimer = -1; const loadWebSeedsData = function() { if ($("prop_webseeds").hasClass("invisible") || $("propertiesPanel_collapseToggle").hasClass("panel-expand")) { @@ -138,6 +138,7 @@ window.qBittorrent.PropWebseeds ??= (() => { const updateData = function() { clearTimeout(loadWebSeedsDataTimer); + loadWebSeedsDataTimer = -1; loadWebSeedsData(); }; diff --git a/src/webui/www/private/scripts/search.js b/src/webui/www/private/scripts/search.js index 133319f0b..72b447b49 100644 --- a/src/webui/www/private/scripts/search.js +++ b/src/webui/www/private/scripts/search.js @@ -47,7 +47,7 @@ window.qBittorrent.Search ??= (() => { }; const searchTabIdPrefix = "Search-"; - let loadSearchPluginsTimer; + let loadSearchPluginsTimer = -1; const searchPlugins = []; let prevSearchPluginsResponse; let selectedCategory = "QBT_TR(All categories)QBT_TR[CONTEXT=SearchEngineWidget]"; @@ -207,7 +207,7 @@ window.qBittorrent.Search ??= (() => { rowId: 0, selectedRowIds: [], running: true, - loadResultsTimer: null, + loadResultsTimer: -1, sort: { column: searchResultsTable.sortedColumn, reverse: searchResultsTable.reverseSort }, }); updateSearchResultsData(searchId); @@ -507,6 +507,7 @@ window.qBittorrent.Search ??= (() => { }, onClose: function() { clearTimeout(loadSearchPluginsTimer); + loadSearchPluginsTimer = -1; } }); } @@ -569,6 +570,7 @@ window.qBittorrent.Search ??= (() => { if (state) { state.running = false; clearTimeout(state.loadResultsTimer); + state.loadResultsTimer = -1; } };