WebUI: Add 'Confirm torrent recheck' option

This PR adds setting & confirmation dialog for torrent recheck.

Closes #19557.
PR #21348.
This commit is contained in:
skomerko 2024-09-22 08:12:44 +02:00 committed by GitHub
parent 183c7c75b1
commit c3224459db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 136 additions and 24 deletions

View file

@ -48,14 +48,24 @@ window.qBittorrent.Dialog ??= (() => {
const deepFreeze = (obj) => {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#examples
// accounts for circular refs
const frozen = new WeakSet();
const deepFreezeSafe = (obj) => {
if (frozen.has(obj))
return;
const keys = Reflect.ownKeys(obj);
for (const key of keys) {
const value = obj[key];
if ((value && (typeof value === "object")) || (typeof value === "function"))
deepFreeze(value);
}
Object.freeze(obj);
frozen.add(obj);
const keys = Reflect.ownKeys(obj);
for (const key of keys) {
const value = obj[key];
if ((value && (typeof value === "object")) || (typeof value === "function"))
deepFreezeSafe(value);
}
Object.freeze(obj);
};
deepFreezeSafe(obj);
};
const baseModalOptions = Object.assign(Object.create(null), {
@ -76,7 +86,11 @@ window.qBittorrent.Dialog ??= (() => {
left: 5
},
resizable: true,
width: 480
width: 480,
onCloseComplete: function() {
// make sure overlay is properly hidden upon modal closing
document.getElementById("modalOverlay").style.display = "none";
}
});
deepFreeze(baseModalOptions);
@ -541,15 +555,31 @@ const initializeWindows = function() {
recheckFN = function() {
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: "api/v2/torrents/recheck",
method: "post",
data: {
hashes: hashes.join("|"),
}
}).send();
updateMainData();
if (hashes.length > 0) {
if (window.qBittorrent.Cache.preferences.get().confirm_torrent_recheck) {
new MochaUI.Modal({
...window.qBittorrent.Dialog.baseModalOptions,
id: "confirmRecheckDialog",
title: "QBT_TR(Recheck confirmation)QBT_TR[CONTEXT=confirmRecheckDialog]",
data: { hashes: hashes },
contentURL: "views/confirmRecheck.html"
});
}
else {
new Request({
url: "api/v2/torrents/recheck",
method: "post",
data: {
"hashes": hashes.join("|"),
},
onSuccess: function() {
updateMainData();
},
onFailure: function() {
alert("QBT_TR(Unable to recheck torrents.)QBT_TR[CONTEXT=HttpServer]");
}
}).send();
}
}
};