Repository navigation
fix(dialogs): close the Add Torrent dialog after a confirmed add - #14
Conversation
|
Hey @fullerhkz, thanks for putting this together, it works on ruTorrent 5.3.19. I tested it on 5.3.18 too though, and a few things need changing:
The version below fixes all three. It reads the result ruTorrent sends back ( Replace your block after /* Core empties #torrent_file and #url with .val(""), which fires no
* event: on every open (beforeShow) and after a confirmed add
* (addTorrentFinished). Re-read both so the chips and Add match. */
var opened = 0;
function resync() {
dz.renderChips();
syncAdd();
}
if (window.theDialogManager && theDialogManager.addHandler) {
theDialogManager.addHandler("tadd", "afterShow", function () { opened++; resync(); });
}
/* Close the dialog once an add is confirmed. Core answers an upload by
* redirecting the hidden frame to addtorrent.php?result[]=<status>&...,
* one final status per item (Success, Duplicate, Failed...), so the frame
* URL says whether anything was added. The source field cannot: ruTorrent
* 5.3.18 and earlier empty it after every answer, refusals included. Only
* a load that follows a real submit counts (the frame also loads once,
* blank, when core inserts it). Add stays disabled while the upload is in
* flight, and an answer that lands after the dialog was closed or reopened
* leaves the dialog alone. */
function addedAny(frame) {
try {
return new URLSearchParams(frame.contentWindow.location.search).getAll("result[]").indexOf("Success") >= 0;
} catch (e) {
return false;
}
}
function closeAfterAdd(form, frameName) {
var frame = document.querySelector('iframe[name="' + frameName + '"]');
if (!form || !frame) return;
var pending = false, sentIn = -1;
form.addEventListener("submit", function (e) {
if (e.defaultPrevented) return;
pending = true;
sentIn = opened;
add.disabled = true;
});
frame.addEventListener("load", function () {
if (!pending) return;
pending = false;
resync();
var dm = window.theDialogManager;
if (addedAny(frame) && sentIn === opened && dm && dm.visible && dm.visible.indexOf("tadd") >= 0) {
dm.hide("tadd");
}
});
}
closeAfterAdd(formFile, "uploadfrm");
closeAfterAdd(formUrl, "uploadfrmurl");Also please point the PR at Thanks again! |
Core ruTorrent never hides the Add Torrent dialog after an add, so it stayed
open after every success and had to be closed by hand. Core also empties the
file and URL fields with .val(""), which fires no event, so the file chip and
the Add button kept showing the previous file the next time the dialog opened.
Read the result ruTorrent redirects the hidden frame to
(addtorrent.php?result[]=<status>), which works on every ruTorrent version,
and hide the dialog only when at least one item was added. Re-sync the chips
and the Add button on every open and after every answer, keep Add disabled
while an upload is in flight, and leave the dialog alone when an answer lands
after it was closed or reopened.
Co-authored-by: JMSDOnline <16356910+JMSDOnline@users.noreply.github.com>
b1f6937 to
7648820
Compare
|
Thanks a lot for testing on 5.3.18 and for the rewrite, @JMSDOnline. You're right: I only tested on 5.3.19, where the field stays filled after a refusal, so I used "field is empty" as the success signal. Reading Updated the PR:
I re-ran the scenarios in headless Chrome against a copy of a real ruTorrent 5.3.19 instance, with
I could not run a real 5.3.18, so that last pair is simulated by making I'm also running this build on my own instance now. |
|
Checked it, the code matches what I tested and the checks pass on my end. Merging into |
|
Awesome, glad everything checks out! Thanks again for the help and for getting this merged. My pleasure contributing to the project! |
Fixes #13: the Add Torrent dialog stays open after a successful add.
What changed
js/dialogs.js, inenhanceAddTorrent(): after the existingsyncAdd()call, listen for the end of an upload this dialog started (an uncancelledsubmit, then theloadof the matching hidden iframeuploadfrm/uploadfrmurl). Core's load handler (addTorrentFinishedincontent.js) is registered first, so by the time ours runs the source field already reflects the server answer:change/inputon it so the file chips and the Add button re-sync, thentheDialogManager.hide("tadd");init.jscarries the regeneratedCQB_REV(bash bin/stamp.sh --write), as in earlier fix commits.CHANGELOG.mdandchangelogs/are untouched, since the release automation writes them.Verification
bash bin/ci-local.sh: ALL GREEN (conventional commit, version consistency,node --check, string catalog, stamp check, selftests).POST php/addtorrent.phpwas intercepted and answered with the same302toaddtorrent.php?result[]=<status>&name[]=...the real server sends, so the real ruTorrent code rendered the toasts and nothing was added.Also confirmed on the live instance.
Not tested: the stock ruTorrent theme and the Create / RSS / other add dialogs (they do not use this code path).
Disclosure
The investigation and the patch were prepared with the help of an AI assistant (Claude, via OpenClaw) and verified in a real browser by the submitter. Please review it like any other change.