feat: stop every download at once

A stop button appears beside Download all whenever anything is
downloading or waiting to, and disappears when nothing is. It kills the
running processes, marks everything the database still calls queued or
running as cancelled, and clears the part files. Downloads already
finished are untouched.

That also covers two cases a per-video Cancel cannot reach: a download
parked on a slot, which stands down when its turn comes, and a row left
"running" by a crash that no process backs any more.

Cancelling no longer reports itself as a failure. download_video
returned Err("Download was cancelled.") when it found its child gone,
which the caller turned into an error dialog — pressing Stop all would
have raised one per download. Stopping something is a normal outcome:
the state is already recorded and the event already sent, so it returns
cleanly.
This commit is contained in:
vincent
2026-08-29 16:31:41 +02:00
parent 5b2be50852
commit 967bcdde93
6 changed files with 127 additions and 8 deletions
+28
View File
@@ -603,6 +603,19 @@ impl Db {
rows.collect::<Result<Vec<_>, _>>().map_err(|e| e.to_string())
}
/// Videos the database still considers in flight. Includes any left
/// "running" by a crash, which no live process backs any more.
pub fn active_downloads(&self) -> Result<Vec<String>, String> {
let mut stmt = self
.conn
.prepare("SELECT video_id FROM downloads WHERE state IN ('queued','running')")
.map_err(|e| e.to_string())?;
let rows = stmt
.query_map([], |r| r.get::<_, String>(0))
.map_err(|e| e.to_string())?;
rows.collect::<Result<Vec<_>, _>>().map_err(|e| e.to_string())
}
pub fn clear_all_downloads(&self) -> Result<usize, String> {
let n = self
.conn
@@ -1020,6 +1033,21 @@ mod tests {
);
}
#[test]
fn active_downloads_are_the_queued_and_running_ones() {
let db = seeded();
db.set_download_state("a", DownloadState::Running, None).unwrap();
db.set_download_state("b", DownloadState::Queued, None).unwrap();
db.set_download_state("c", DownloadState::Done, None).unwrap();
let mut active = db.active_downloads().unwrap();
active.sort();
assert_eq!(active, vec!["a".to_string(), "b".to_string()]);
// Stopping them takes them out of flight without deleting anything.
db.set_download_state("a", DownloadState::Cancelled, None).unwrap();
db.set_download_state("b", DownloadState::Cancelled, None).unwrap();
assert!(db.active_downloads().unwrap().is_empty());
}
#[test]
fn clearing_a_download_makes_it_undownloaded_again() {
let db = seeded();