mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-06 05:01:25 -07:00
WebUI: Don't update UI if the page is hidden
Currently, there is unnecessary CPU/network usage by the web UI when it's running in the background, this PR prevents it from refreshing in the background. Closes #22565. PR #22567.
This commit is contained in:
parent
0187f19f60
commit
0160aa28b6
7 changed files with 30 additions and 0 deletions
|
@ -750,6 +750,8 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||
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({
|
||||
|
@ -1774,6 +1776,21 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
addEventListener("visibilitychange", (event) => {
|
||||
if (document.hidden)
|
||||
return;
|
||||
|
||||
switch (LocalPreferences.get("selected_window_tab")) {
|
||||
case "log":
|
||||
window.qBittorrent.Log.load();
|
||||
break;
|
||||
case "transfers":
|
||||
syncData(100);
|
||||
updatePropertiesPanel();
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener("load", async () => {
|
||||
|
|
|
@ -305,6 +305,8 @@ window.qBittorrent.PropFiles ??= (() => {
|
|||
|
||||
let loadTorrentFilesDataTimer = -1;
|
||||
const loadTorrentFilesData = () => {
|
||||
if (document.hidden)
|
||||
return;
|
||||
if ($("propFiles").classList.contains("invisible")
|
||||
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
||||
// Tab changed, don't do anything
|
||||
|
|
|
@ -76,6 +76,8 @@ window.qBittorrent.PropGeneral ??= (() => {
|
|||
|
||||
let loadTorrentDataTimer = -1;
|
||||
const loadTorrentData = () => {
|
||||
if (document.hidden)
|
||||
return;
|
||||
if ($("propGeneral").classList.contains("invisible")
|
||||
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
||||
// Tab changed, don't do anything
|
||||
|
|
|
@ -43,6 +43,8 @@ window.qBittorrent.PropPeers ??= (() => {
|
|||
let show_flags = true;
|
||||
|
||||
const loadTorrentPeersData = () => {
|
||||
if (document.hidden)
|
||||
return;
|
||||
if ($("propPeers").classList.contains("invisible")
|
||||
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
||||
syncTorrentPeersLastResponseId = 0;
|
||||
|
|
|
@ -43,6 +43,8 @@ window.qBittorrent.PropTrackers ??= (() => {
|
|||
let loadTrackersDataTimer = -1;
|
||||
|
||||
const loadTrackersData = () => {
|
||||
if (document.hidden)
|
||||
return;
|
||||
if ($("propTrackers").classList.contains("invisible")
|
||||
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
||||
// Tab changed, don't do anything
|
||||
|
|
|
@ -43,6 +43,8 @@ window.qBittorrent.PropWebseeds ??= (() => {
|
|||
|
||||
let loadWebSeedsDataTimer = -1;
|
||||
const loadWebSeedsData = () => {
|
||||
if (document.hidden)
|
||||
return;
|
||||
if ($("propWebSeeds").classList.contains("invisible")
|
||||
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
||||
// Tab changed, don't do anything
|
||||
|
|
|
@ -336,6 +336,9 @@
|
|||
};
|
||||
|
||||
const syncLogData = (curTab) => {
|
||||
if (document.hidden)
|
||||
return;
|
||||
|
||||
if (curTab === undefined)
|
||||
curTab = currentSelectedTab;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue