mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 04:49:47 -07:00
Merge pull request #21117 from Chocobo1/webui_interval
WebUI: timer related clean ups
This commit is contained in:
commit
9d494e84bf
11 changed files with 52 additions and 49 deletions
|
@ -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;
|
||||||
|
|
|
@ -91,54 +91,43 @@ window.qBittorrent.DynamicTable ??= (() => {
|
||||||
},
|
},
|
||||||
|
|
||||||
setupCommonEvents: function() {
|
setupCommonEvents: function() {
|
||||||
const scrollFn = function() {
|
const tableDiv = $(this.dynamicTableDivId);
|
||||||
$(this.dynamicTableFixedHeaderDivId).getElements("table")[0].style.left = -$(this.dynamicTableDivId).scrollLeft + "px";
|
const tableFixedHeaderDiv = $(this.dynamicTableFixedHeaderDivId);
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
$(this.dynamicTableDivId).addEvent("scroll", scrollFn);
|
tableDiv.addEventListener("scroll", () => {
|
||||||
|
tableFixedHeaderDiv.getElements("table")[0].style.left = `${-tableDiv.scrollLeft}px`;
|
||||||
|
});
|
||||||
|
|
||||||
// if the table exists within a panel
|
// if the table exists within a panel
|
||||||
if ($(this.dynamicTableDivId).getParent(".panel")) {
|
const parentPanel = tableDiv.getParent(".panel");
|
||||||
const resizeFn = function() {
|
if (parentPanel) {
|
||||||
const panel = $(this.dynamicTableDivId).getParent(".panel");
|
const resizeFn = (entries) => {
|
||||||
let h = panel.getBoundingClientRect().height - $(this.dynamicTableFixedHeaderDivId).getBoundingClientRect().height;
|
const panel = entries[0].target;
|
||||||
$(this.dynamicTableDivId).style.height = h + "px";
|
let h = panel.getBoundingClientRect().height - tableFixedHeaderDiv.getBoundingClientRect().height;
|
||||||
|
tableDiv.style.height = `${h}px`;
|
||||||
|
|
||||||
// Workaround due to inaccurate calculation of elements heights by browser
|
// Workaround due to inaccurate calculation of elements heights by browser
|
||||||
|
|
||||||
let n = 2;
|
let n = 2;
|
||||||
|
|
||||||
// is panel vertical scrollbar visible or does panel content not fit?
|
// is panel vertical scrollbar visible or does panel content not fit?
|
||||||
while (((panel.clientWidth !== panel.offsetWidth) || (panel.clientHeight !== panel.scrollHeight)) && (n > 0)) {
|
while (((panel.clientWidth !== panel.offsetWidth) || (panel.clientHeight !== panel.scrollHeight)) && (n > 0)) {
|
||||||
--n;
|
--n;
|
||||||
h -= 0.5;
|
h -= 0.5;
|
||||||
$(this.dynamicTableDivId).style.height = h + "px";
|
tableDiv.style.height = `${h}px`;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.lastPanelHeight = panel.getBoundingClientRect().height;
|
this.resizeDebounceTimer = -1;
|
||||||
}.bind(this);
|
const resizeDebouncer = (entries) => {
|
||||||
|
clearTimeout(this.resizeDebounceTimer);
|
||||||
|
this.resizeDebounceTimer = setTimeout(() => {
|
||||||
|
resizeFn(entries);
|
||||||
|
resizeDebounceTimer = -1;
|
||||||
|
}, 100);
|
||||||
|
};
|
||||||
|
|
||||||
$(this.dynamicTableDivId).getParent(".panel").addEvent("resize", resizeFn);
|
const resizeObserver = new ResizeObserver(resizeDebouncer);
|
||||||
|
resizeObserver.observe(parentPanel, { box: "border-box" });
|
||||||
this.lastPanelHeight = 0;
|
|
||||||
|
|
||||||
// Workaround. Resize event is called not always (for example it isn't called when browser window changes it's size)
|
|
||||||
|
|
||||||
const checkResizeFn = function() {
|
|
||||||
const tableDiv = $(this.dynamicTableDivId);
|
|
||||||
|
|
||||||
// dynamicTableDivId is not visible on the UI
|
|
||||||
if (!tableDiv)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const panel = tableDiv.getParent(".panel");
|
|
||||||
if (this.lastPanelHeight !== panel.getBoundingClientRect().height) {
|
|
||||||
this.lastPanelHeight = panel.getBoundingClientRect().height;
|
|
||||||
panel.fireEvent("resize");
|
|
||||||
}
|
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
setInterval(checkResizeFn, 500);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ window.qBittorrent.PiecesBar ??= (() => {
|
||||||
if (vals.width > 0)
|
if (vals.width > 0)
|
||||||
obj.setPieces(vals.pieces);
|
obj.setPieces(vals.pieces);
|
||||||
else
|
else
|
||||||
setTimeout(() => { checkForParent(obj.id); }, 1);
|
setTimeout(() => { checkForParent(obj.id); });
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ window.qBittorrent.PiecesBar ??= (() => {
|
||||||
if (!obj)
|
if (!obj)
|
||||||
return;
|
return;
|
||||||
if (!obj.parentNode)
|
if (!obj.parentNode)
|
||||||
return setTimeout(() => { checkForParent(id); }, 1);
|
return setTimeout(() => { checkForParent(id); }, 100);
|
||||||
|
|
||||||
obj.refresh();
|
obj.refresh();
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ window.qBittorrent.ProgressBar ??= (() => {
|
||||||
if (vals.width)
|
if (vals.width)
|
||||||
obj.setValue(vals.value);
|
obj.setValue(vals.value);
|
||||||
else
|
else
|
||||||
setTimeout('ProgressBar_checkForParent("' + obj.id + '")', 1);
|
setTimeout('ProgressBar_checkForParent("' + obj.id + '")');
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -144,7 +144,7 @@ window.qBittorrent.ProgressBar ??= (() => {
|
||||||
if (!obj)
|
if (!obj)
|
||||||
return;
|
return;
|
||||||
if (!obj.parentNode)
|
if (!obj.parentNode)
|
||||||
return setTimeout('ProgressBar_checkForParent("' + id + '")', 1);
|
return setTimeout('ProgressBar_checkForParent("' + id + '")', 100);
|
||||||
obj.setStyle("width", "100%");
|
obj.setStyle("width", "100%");
|
||||||
const w = obj.offsetWidth;
|
const w = obj.offsetWidth;
|
||||||
obj.vals.dark.setStyle("width", w);
|
obj.vals.dark.setStyle("width", w);
|
||||||
|
|
|
@ -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();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@
|
||||||
const serverSyncRssDataInterval = 1500;
|
const serverSyncRssDataInterval = 1500;
|
||||||
let feedData = {};
|
let feedData = {};
|
||||||
let pathByFeedId = new Map();
|
let pathByFeedId = new Map();
|
||||||
let feedRefreshTimer;
|
let feedRefreshTimer = -1;
|
||||||
const rssFeedTable = new window.qBittorrent.DynamicTable.RssFeedTable();
|
const rssFeedTable = new window.qBittorrent.DynamicTable.RssFeedTable();
|
||||||
const rssArticleTable = new window.qBittorrent.DynamicTable.RssArticleTable();
|
const rssArticleTable = new window.qBittorrent.DynamicTable.RssArticleTable();
|
||||||
|
|
||||||
|
@ -293,11 +293,15 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const unload = () => {
|
const unload = () => {
|
||||||
clearInterval(feedRefreshTimer);
|
clearTimeout(feedRefreshTimer);
|
||||||
|
feedRefreshTimer = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
const load = () => {
|
const load = () => {
|
||||||
feedRefreshTimer = setInterval(updateRssFeedList, serverSyncRssDataInterval);
|
feedRefreshTimer = setTimeout(() => {
|
||||||
|
updateRssFeedList();
|
||||||
|
load();
|
||||||
|
}, serverSyncRssDataInterval);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addRSSFeed = () => {
|
const addRSSFeed = () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue