misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
Cancel in Download File Info asks whether to cancel the waiting downloads too (#394) (#610)
Yuhan Chena255a8b1f185
diff --git a/ROADMAP.md b/ROADMAP.mdindex 25da91e1..2492764b 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -555,6 +555,9 @@ These ship in a later version, when they're ready.([#357](https://github.com/anefzaoui/misterdownloadmanager/issues/357)): the last one in review- π The browser extension's media list naming a file after its page, as an option: in review- π Malay: a native speaker's check of the menus, toolbar and list columns: in review+- π Cancel in Download File Info asking whether the downloads waiting behind it are cancelled+ too (a browser selection's arrive one by one)+ ([#394](https://github.com/anefzaoui/misterdownloadmanager/issues/394)): in review### Bugs being looked intodiff --git a/crates/app/src/app.rs b/crates/app/src/app.rsindex d6563d97..bc95792c 100644--- a/crates/app/src/app.rs+++ b/crates/app/src/app.rs@@ -8669,6 +8669,9 @@ impl App {}if let Some(mut fi) = self.file_info.take() {self.start_early(&mut fi);+ // The downloads waiting their turn behind this one (a browser selection's arrive+ // one by one): Cancel asks whether they are cancelled too (#394).+ fi.waiting = self.file_info_waiting.len();let out = fi.show(ctx, &mut self.icons);if std::mem::take(&mut fi.new_category) {self.category_for_file_info = true;@@ -8699,6 +8702,12 @@ impl App {match out {Outcome::Open => self.file_info = Some(fi),Outcome::Closed => {+ if fi.cancel_all {+ // #394: "Yes" to "Cancel them too?": the browser's links waiting+ // behind this one are cancelled with it (the browser gave its own copy+ // up, and Download File Info was their step).+ self.file_info_waiting.clear();+ }if let Some(id) = fi.early {self.stop(id);self.after_stop.push((id, None));diff --git a/crates/app/src/dialogs.rs b/crates/app/src/dialogs.rsindex db79499f..2a5a6e50 100644--- a/crates/app/src/dialogs.rs+++ b/crates/app/src/dialogs.rs@@ -878,6 +878,14 @@ pub struct FileInfo {folders_open: bool,/// "+" was clicked: the app opens the new-category window.pub new_category: bool,+ /// The downloads waiting their turn behind this one (a browser selection's arrive one by+ /// one): Cancel asks whether they are cancelled too (#394). The app sets it each frame.+ pub waiting: usize,+ /// Cancel was pressed while some waited: the question is up, this dialog waits for it.+ cancel_ask: bool,+ /// The question's answer was Yes: the waiting ones are cancelled with this one (`Closed`+ /// comes with it; the app clears the waiting ones).+ pub cancel_all: bool,/// The debrid accounts (#44): which one this address goes through, if any.route: crate::debrid::Route,/// The account that takes the address ("Real-Debrid (labuser)"), as last looked at: the@@ -968,6 +976,9 @@ impl FileInfo {folders: Vec::new(),folders_open: false,new_category: false,+ waiting: 0,+ cancel_ask: false,+ cancel_all: false,route,through,direct,@@ -1121,7 +1132,30 @@ impl FileInfo {.map(Path::to_path_buf).unwrap_or_default();let out = self.dialog(ctx, icons);- ensure_folder(ctx, &mut self.asking, out, &folder)+ let out = ensure_folder(ctx, &mut self.asking, out, &folder);+ // #394: more downloads wait their turn behind this one (the browser's selected links):+ // Cancel (the button, Escape, the window's Γ) asks whether they are cancelled too.+ if matches!(out, Outcome::Closed) && self.waiting > 0 && !self.cancel_ask {+ self.cancel_ask = true;+ }+ if self.cancel_ask {+ // The question answers for the dialog: a Start pressed meanwhile waits for it, as+ // with the Create folder question.+ return match cancel_waiting(ctx, self.waiting) {+ Outcome::Done(all) => {+ self.cancel_ask = false;+ self.cancel_all = all;+ Outcome::Closed+ }+ // The question's own Γ: as No, this one alone is skipped.+ Outcome::Closed => {+ self.cancel_ask = false;+ Outcome::Closed+ }+ Outcome::Open => Outcome::Open,+ };+ }+ out}fn dialog(@@ -1553,6 +1587,68 @@ impl FileInfo {}}+/// Cancel in Download File Info while more downloads wait their turn behind it (#394): are+/// those cancelled too? `Done(true)`: yes; `Done(false)`: this one alone is skipped.+fn cancel_waiting(ctx: &egui::Context, n: usize) -> Outcome<bool> {+ let extra = grow_extra(ctx, "cancel-waiting");+ question(+ ctx,+ "cancel-waiting",+ "Mister Download Manager",+ [374.0, 100.0 + extra],+ false,+ winui::BG(),+ |ui, o| {+ let p = ui.painter().clone();+ let text = crate::i18n::fmt(+ // i18n: Cancel in Download File Info with downloads waiting behind it+ &crate::i18n::tn(+ n as u64,+ "There is {n} more download waiting. Cancel it too?",+ "There are {n} more downloads waiting. Cancel them too?",+ ),+ &[("n", &crate::i18n::integer(n as u64))],+ );+ let lines = winui::paragraph(+ &p,+ o.x + 11.0,+ o.y + 21.0,+ &text,+ winui::TEXT(),+ o.x + 362.0,+ 13.0,+ );+ grow_to(ui.ctx(), "cancel-waiting", lines, 2);+ let o = o + vec2(0.0, extra);+ let yes = winui::button(+ ui,+ r(o, 94.0, 63.0, 73.0, 21.0),+ "Yes",+ ButtonKind::Default,+ false,+ None,+ )+ .clicked();+ let no = winui::button(+ ui,+ r(o, 207.0, 63.0, 73.0, 21.0),+ "No",+ ButtonKind::Normal,+ false,+ None,+ )+ .clicked();+ if no || winui::escape_pressed(ui) {+ Outcome::Done(false)+ } else if yes || winui::enter_pressed(ui) {+ Outcome::Done(true)+ } else {+ Outcome::Open+ }+ },+ )+}+/// Look `url` up in the background (name, size) as the download will ask it (`request`), the/// answer landing in the slot returned./// A look's result: what it learned, and its open answer when the download can read it.@@ -3207,6 +3303,64 @@ mod tests {assert!(!pass(true));}+ /// #394: the question's answers: Enter ("Yes", the default) cancels the waiting ones too,+ /// Escape ("No") skips this one alone, and with no answer nothing is decided.+ #[test]+ fn cancel_waiting_answers_enter_escape_and_nothing() {+ // The key a pass presses, delivered to the window that renders the question (a+ // thread-local: the renderer is global, and another test's window must see no key).+ thread_local! {+ static KEY: std::cell::Cell<Option<egui::Key>> = const { std::cell::Cell::new(None) };+ }+ egui::Context::set_immediate_viewport_renderer(move |ctx, viewport| {+ let events = KEY.with(|k| {+ k.take().map(|key| {+ vec![egui::Event::Key {+ key,+ physical_key: None,+ pressed: true,+ repeat: false,+ modifiers: egui::Modifiers::default(),+ }]+ })+ });+ let input = egui::RawInput {+ viewport_id: viewport.ids.this,+ events: events.unwrap_or_default(),+ viewports: std::iter::once((viewport.ids.this, egui::ViewportInfo::default()))+ .collect(),+ screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(400.0, 120.0))),+ ..Default::default()+ };+ let mut ui_cb = viewport.viewport_ui_cb;+ let mut out = ctx.run_ui(input, |ui| ui_cb(ui));+ out.textures_delta.clear();+ });+ let ctx = egui::Context::default();+ ctx.set_embed_viewports(false);+ // A pass of the question, with a key pressed in it (or not); the answer it gave.+ let pass = |key: Option<egui::Key>, answer: &std::cell::Cell<Option<Outcome<bool>>>| {+ KEY.with(|k| k.set(key));+ let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {+ answer.set(Some(cancel_waiting(ui.ctx(), 2)));+ });+ out.textures_delta.clear();+ answer.take()+ };+ let answer = std::cell::Cell::new(None);+ assert!(matches!(pass(None, &answer), Some(Outcome::Open)));+ assert!(matches!(+ pass(Some(egui::Key::Enter), &answer),+ Some(Outcome::Done(true))+ ));+ // Opened again: a new question.+ assert!(matches!(pass(None, &answer), Some(Outcome::Open)));+ assert!(matches!(+ pass(Some(egui::Key::Escape), &answer),+ Some(Outcome::Done(false))+ ));+ }+/// Add URL opens and its address box takes the focus, frame after frame, without the app/// hanging (0.2.2 froze here: an editable drop-down asked egui's context inside its lock).#[test]diff --git a/i18n/en.tsv b/i18n/en.tsvindex b3a19e02..bf030d54 100644--- a/i18n/en.tsv+++ b/i18n/en.tsv@@ -33,6 +33,10 @@#. {n} = a number (keep the braces as they are)@plural Matches {n} article now (it adds new ones only):|Matches {n} articles now (it adds new ones only): Matches {n} article now (it adds new ones only):|Matches {n} articles now (it adds new ones only):#. count in a dialog box+#. Cancel in Download File Info with downloads waiting behind it+#. {n} = a number (keep the braces as they are)+@plural There is {n} more download waiting. Cancel it too?|There are {n} more downloads waiting. Cancel them too? There is {n} more download waiting. Cancel it too?|There are {n} more downloads waiting. Cancel them too?+#. count in a dialog box#. "files already there" question, under the first path: {n} = how many more#. {n} = a number (keep the braces as they are)@plural and {n} other file|and {n} other files and {n} other file|and {n} other files