Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Stop stays stopped in a running queue (#341) (#386)

Ahmed Nefzaoui553ccda8f51c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7c70e88d..bc19c900 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- **Stop** on a download in a running queue stays stopped, instead of the queue starting it again a moment later; **Stop All** too ([#341](https://github.com/anefzaoui/misterdownloadmanager/issues/341)).
- Removing the last feed in the RSS feeds window no longer crashes the app ([#321](https://github.com/anefzaoui/misterdownloadmanager/issues/321)).
- **YouTube formats with Node.js or Bun installed** ([#360](https://github.com/anefzaoui/misterdownloadmanager/issues/360)): yt-dlp needs a JavaScript runtime for them and looks for Deno alone, so MDM now tells it about Node.js (nvm's too) or Bun when there is no Deno.
- **YouTube's look-up failing with "Requested format is not available"** ([#352](https://github.com/anefzaoui/misterdownloadmanager/issues/352)): signed-in cookies make yt-dlp use only YouTube's players that need a JavaScript runtime, and without one no video is left. The page is now looked up again without the cookies, and lists its qualities.
diff --git a/ROADMAP.md b/ROADMAP.md
index 9f469aae..07eac297 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -463,6 +463,7 @@ These ship in a later version, when they're ready.
### Bugs being looked into
+- πŸ”„ A download starting again by itself after Stop, when it is in a running queue\n ([#341](https://github.com/anefzaoui/misterdownloadmanager/issues/341)): fix in review
- πŸ”„ A crash when removing the last feed in the RSS feeds window
([#321](https://github.com/anefzaoui/misterdownloadmanager/issues/321)): fix in review
- πŸ”„ **Open folder** on a torrent still downloading
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index 9f999052..b7cea726 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -575,6 +575,9 @@ pub struct App {
queues: Vec<Queue>,
/// Failure time and count per download, for queue retries.
failures: HashMap<u64, (Instant, u32)>,
+ /// Stopped by hand while they could have run: a running queue leaves them alone until
+ /// they are started again or the queue is started anew (#341).
+ stopped_by_hand: std::collections::HashSet<u64>,
/// Seconds since local midnight at the last scheduler tick.
clock: u32,
/// Scheduler β†’ "Wake the computer to run this queue": the wake set with the system (#142).
@@ -1032,6 +1035,7 @@ impl App {
last_layout: None,
queues,
failures: HashMap::new(),
+ stopped_by_hand: Default::default(),
clock: seconds_now(),
wake: Default::default(),
commands,
@@ -2268,6 +2272,7 @@ impl App {
/// Start or resume a download; `show` opens its progress dialog (IDM's default).
fn start(&mut self, id: u64, show: bool) {
+ self.stopped_by_hand.remove(&id);
let rt = self.rt.clone();
let Some(item) = self.item(id) else { return };
// A finished gallery may start again: it fetches the files not there yet (#58).
@@ -2409,11 +2414,21 @@ impl App {
}
}
+ /// The user's Stop (or Pause): it stays stopped, even in a queue that is running (#341).
+ fn stop_by_hand(&mut self, id: u64) {
+ self.stop(id);
+ self.stopped_by_hand.insert(id);
+ }
+
fn stop_all(&mut self) {
- for i in &self.items {
- if let Some(l) = &i.live {
- l.dl.cancel();
- }
+ let running: Vec<u64> = self
+ .items
+ .iter()
+ .filter(|i| i.live.is_some())
+ .map(|i| i.id)
+ .collect();
+ for id in running {
+ self.stop_by_hand(id);
}
}
@@ -4354,7 +4369,7 @@ impl App {
let why = match action {
"pause" if !running => Some("not running"),
"pause" => {
- self.stop(id);
+ self.stop_by_hand(id);
None
}
"start" if running => Some("already running"),
@@ -4472,6 +4487,9 @@ impl App {
self.sound(2);
}
self.queues[q].running = true;
+ for id in &self.queues[q].items {
+ self.stopped_by_hand.remove(id);
+ }
self.tick_queues();
}
@@ -4494,6 +4512,7 @@ impl App {
fn member_of(&self, i: &Item, now: Instant) -> Member {
let id = i.id;
match i.status {
+ Status::Stopped if self.stopped_by_hand.contains(&id) => Member::Held,
Status::Queued | Status::Stopped => Member::Waiting,
Status::Downloading => Member::Running,
Status::Complete => Member::Complete,
@@ -4680,7 +4699,7 @@ impl App {
Cmd::Stop => {
for id in many {
if self.item(id).is_some_and(|i| i.live.is_some()) {
- self.stop(id);
+ self.stop_by_hand(id);
}
}
}
@@ -8122,7 +8141,7 @@ impl App {
for (id, a) in actions {
match a {
progress::Action::None => {}
- progress::Action::Pause => self.stop(id),
+ progress::Action::Pause => self.stop_by_hand(id),
progress::Action::Resume => self.start(id, true),
progress::Action::Cancel => {
self.stop(id);
diff --git a/crates/app/src/queue.rs b/crates/app/src/queue.rs
index ec73cf4a..ee10737c 100644
--- a/crates/app/src/queue.rs
+++ b/crates/app/src/queue.rs
@@ -139,6 +139,8 @@ impl Queue {
pub enum Member {
/// Not started, or stopped: can start now.
Waiting,
+ /// Stopped by hand while the queue runs: left alone until started again (#341).
+ Held,
Running,
Complete,
/// Failed `tries` times, last at `at`.
@@ -168,7 +170,7 @@ pub fn to_start(q: &Queue, member: impl Fn(u64) -> Member, now: Instant) -> Vec<
q.schedule.retries.is_none_or(|max| tries < max)
&& now.duration_since(at) >= RETRY_DELAY
}
- Member::Running | Member::Complete => false,
+ Member::Running | Member::Complete | Member::Held => false,
};
if ready {
out.push(*id);
@@ -184,7 +186,7 @@ pub fn finished(q: &Queue, member: impl Fn(u64) -> Member) -> bool {
q.items.iter().all(|id| match member(*id) {
Member::Complete => true,
Member::Failed { tries, .. } => q.schedule.retries.is_some_and(|max| tries >= max),
- Member::Waiting | Member::Running => false,
+ Member::Waiting | Member::Held | Member::Running => false,
})
}
@@ -233,6 +235,22 @@ mod tests {
assert!(to_start(&q(1, &[1, 2, 3]), st, now).is_empty());
}
+ /// #341: Stop in a running queue is left alone, and the queue isn't over because of it.
+ #[test]
+ fn a_download_stopped_by_hand_is_not_started_again() {
+ let st = |id| {
+ if id == 1 {
+ Member::Held
+ } else {
+ Member::Waiting
+ }
+ };
+ let now = Instant::now();
+ assert_eq!(to_start(&q(2, &[1, 2]), st, now), vec![2]);
+ assert!(to_start(&q(2, &[1]), st, now).is_empty());
+ assert!(!finished(&q(1, &[1]), st));
+ }
+
#[test]
fn failed_files_wait_and_respect_the_retry_limit() {
let t0 = Instant::now();