Add TUI download pause and queued delete

This commit is contained in:
michel
2026-04-26 11:50:37 +02:00
parent 807dea5f17
commit de58c8cbe2
7 changed files with 354 additions and 9 deletions
+64
View File
@@ -238,6 +238,8 @@ impl MainTui {
vec![
("1-3", "focus pane"),
("↑↓", "navigate"),
("p", "pause/resume"),
("d", "delete queued"),
("q", "quit"),
]
}
@@ -617,11 +619,73 @@ impl MainTui {
self.state.downloads_table_state.select(Some(new));
}
}
KeyCode::Char('p') => {
self.toggle_selected_download_pause();
}
KeyCode::Char('d') => {
self.remove_selected_queued_download();
}
_ => {}
}
Ok(())
}
fn toggle_selected_download_pause(&mut self) {
let Some(index) = self.state.downloads_table_state.selected() else {
return;
};
let Some(download_entry) = self.state.downloads.get(index) else {
return;
};
let download = &download_entry.download;
match download.status {
DownloadStatus::InProgress { .. } => {
self.client
.pause_download(&download.username, &download.filename);
}
DownloadStatus::Paused { .. } => {
self.client
.resume_download(&download.username, &download.filename);
}
_ => {}
}
}
fn remove_selected_queued_download(&mut self) {
let Some(index) = self.state.downloads_table_state.selected() else {
return;
};
let Some(download_entry) = self.state.downloads.get(index) else {
return;
};
let download = &download_entry.download;
if !matches!(download.status, DownloadStatus::Queued) {
return;
}
if !self
.client
.remove_queued_download(&download.username, &download.filename)
{
return;
}
self.state.downloads.remove(index);
self.select_download_after_removal(index);
}
fn select_download_after_removal(&mut self, removed_index: usize) {
if self.state.downloads.is_empty() {
self.state.downloads_table_state.select(None);
return;
}
let next_index = removed_index.min(self.state.downloads.len() - 1);
self.state.downloads_table_state.select(Some(next_index));
}
fn handle_mouse_event(&mut self, mouse: MouseEvent) -> Result<()> {
if let MouseEventKind::Down(MouseButton::Left) = mouse.kind {
let (col, row) = (mouse.column, mouse.row);