From e31b553807de7860b95813e8fe79d5ce1862904b Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 12 Feb 2024 14:57:53 +0800 Subject: [PATCH] Stop sync requests after qbt has been shutdown --- src/webui/www/private/scripts/client.js | 28 ++++++++++++++++----- src/webui/www/private/scripts/mocha-init.js | 3 ++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index 2c443d963..ed0fa08cb 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -34,7 +34,9 @@ window.qBittorrent.Client = (() => { return { closeWindows: closeWindows, genHash: genHash, - getSyncMainDataInterval: getSyncMainDataInterval + getSyncMainDataInterval: getSyncMainDataInterval, + isStopped: isStopped, + stop: stop }; }; @@ -56,6 +58,15 @@ window.qBittorrent.Client = (() => { return customSyncMainDataInterval ? customSyncMainDataInterval : serverSyncMainDataInterval; }; + let stopped = false; + const isStopped = () => { + return stopped; + }; + + const stop = () => { + stopped = true; + }; + return exports(); })(); Object.freeze(window.qBittorrent.Client); @@ -654,7 +665,7 @@ window.addEventListener("DOMContentLoaded", function() { }; })(); - let syncMainDataTimer; + let syncMainDataTimeoutID; let syncRequestInProgress = false; const syncMainData = function() { const url = new URI('api/v2/sync/maindata'); @@ -839,10 +850,15 @@ window.addEventListener("DOMContentLoaded", function() { }; const syncData = function(delay) { - if (!syncRequestInProgress) { - clearTimeout(syncMainDataTimer); - syncMainDataTimer = syncMainData.delay(delay); - } + if (syncRequestInProgress) + return; + + clearTimeout(syncMainDataTimeoutID); + + if (window.qBittorrent.Client.isStopped()) + return; + + syncMainDataTimeoutID = syncMainData.delay(delay); }; const processServerState = function() { diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index 671c30041..613f0fe15 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -1159,7 +1159,8 @@ const initializeWindows = function() { onSuccess: function() { document.write(' QBT_TR(qBittorrent has been shutdown)QBT_TR[CONTEXT=HttpServer]

QBT_TR(qBittorrent has been shutdown)QBT_TR[CONTEXT=HttpServer]

'); document.close(); - stop(); + window.stop(); + window.qBittorrent.Client.stop(); } }).send(); }