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 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({
|
||||||
|
@ -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 () => {
|
window.addEventListener("load", async () => {
|
||||||
|
|
|
@ -305,6 +305,8 @@ window.qBittorrent.PropFiles ??= (() => {
|
||||||
|
|
||||||
let loadTorrentFilesDataTimer = -1;
|
let loadTorrentFilesDataTimer = -1;
|
||||||
const loadTorrentFilesData = () => {
|
const loadTorrentFilesData = () => {
|
||||||
|
if (document.hidden)
|
||||||
|
return;
|
||||||
if ($("propFiles").classList.contains("invisible")
|
if ($("propFiles").classList.contains("invisible")
|
||||||
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
||||||
// Tab changed, don't do anything
|
// Tab changed, don't do anything
|
||||||
|
|
|
@ -76,6 +76,8 @@ window.qBittorrent.PropGeneral ??= (() => {
|
||||||
|
|
||||||
let loadTorrentDataTimer = -1;
|
let loadTorrentDataTimer = -1;
|
||||||
const loadTorrentData = () => {
|
const loadTorrentData = () => {
|
||||||
|
if (document.hidden)
|
||||||
|
return;
|
||||||
if ($("propGeneral").classList.contains("invisible")
|
if ($("propGeneral").classList.contains("invisible")
|
||||||
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
||||||
// Tab changed, don't do anything
|
// Tab changed, don't do anything
|
||||||
|
|
|
@ -43,6 +43,8 @@ window.qBittorrent.PropPeers ??= (() => {
|
||||||
let show_flags = true;
|
let show_flags = true;
|
||||||
|
|
||||||
const loadTorrentPeersData = () => {
|
const loadTorrentPeersData = () => {
|
||||||
|
if (document.hidden)
|
||||||
|
return;
|
||||||
if ($("propPeers").classList.contains("invisible")
|
if ($("propPeers").classList.contains("invisible")
|
||||||
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
||||||
syncTorrentPeersLastResponseId = 0;
|
syncTorrentPeersLastResponseId = 0;
|
||||||
|
|
|
@ -43,6 +43,8 @@ window.qBittorrent.PropTrackers ??= (() => {
|
||||||
let loadTrackersDataTimer = -1;
|
let loadTrackersDataTimer = -1;
|
||||||
|
|
||||||
const loadTrackersData = () => {
|
const loadTrackersData = () => {
|
||||||
|
if (document.hidden)
|
||||||
|
return;
|
||||||
if ($("propTrackers").classList.contains("invisible")
|
if ($("propTrackers").classList.contains("invisible")
|
||||||
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
||||||
// Tab changed, don't do anything
|
// Tab changed, don't do anything
|
||||||
|
|
|
@ -43,6 +43,8 @@ window.qBittorrent.PropWebseeds ??= (() => {
|
||||||
|
|
||||||
let loadWebSeedsDataTimer = -1;
|
let loadWebSeedsDataTimer = -1;
|
||||||
const loadWebSeedsData = () => {
|
const loadWebSeedsData = () => {
|
||||||
|
if (document.hidden)
|
||||||
|
return;
|
||||||
if ($("propWebSeeds").classList.contains("invisible")
|
if ($("propWebSeeds").classList.contains("invisible")
|
||||||
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
|| $("propertiesPanel_collapseToggle").classList.contains("panel-expand")) {
|
||||||
// Tab changed, don't do anything
|
// Tab changed, don't do anything
|
||||||
|
|
|
@ -336,6 +336,9 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const syncLogData = (curTab) => {
|
const syncLogData = (curTab) => {
|
||||||
|
if (document.hidden)
|
||||||
|
return;
|
||||||
|
|
||||||
if (curTab === undefined)
|
if (curTab === undefined)
|
||||||
curTab = currentSelectedTab;
|
curTab = currentSelectedTab;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue