Skip to content

Commit

Permalink
Stop sync requests after qbt has been shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobo1 committed Feb 13, 2024
1 parent a9741bb commit e31b553
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
28 changes: 22 additions & 6 deletions src/webui/www/private/scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ window.qBittorrent.Client = (() => {
return {
closeWindows: closeWindows,
genHash: genHash,
getSyncMainDataInterval: getSyncMainDataInterval
getSyncMainDataInterval: getSyncMainDataInterval,
isStopped: isStopped,
stop: stop
};
};

Expand All @@ -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);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/webui/www/private/scripts/mocha-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,8 @@ const initializeWindows = function() {
onSuccess: function() {
document.write('<!doctype html><html lang="${LANG}"><head> <meta charset="UTF-8"> <meta name="color-scheme" content="light dark" /> <title>QBT_TR(qBittorrent has been shutdown)QBT_TR[CONTEXT=HttpServer]</title></head><body> <h1 style="text-align: center;">QBT_TR(qBittorrent has been shutdown)QBT_TR[CONTEXT=HttpServer]</h1></body></html>');
document.close();
stop();
window.stop();
window.qBittorrent.Client.stop();
}
}).send();
}
Expand Down

0 comments on commit e31b553

Please sign in to comment.