From e9c24076fd09674e5216392b44ee390e9fffc384 Mon Sep 17 00:00:00 2001 From: aidanaden Date: Fri, 12 Jul 2024 10:26:32 +0800 Subject: [PATCH] feat: add progress status for moving torrents --- rm-main/src/transmission/action.rs | 25 +++++++++++-------- rm-main/src/ui/tabs/torrents/task_manager.rs | 1 + .../ui/tabs/torrents/tasks/move_torrent.rs | 6 ++--- rm-main/src/ui/tabs/torrents/tasks/status.rs | 12 +++++++++ rm-shared/src/status_task.rs | 1 + 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/rm-main/src/transmission/action.rs b/rm-main/src/transmission/action.rs index 4e8b956..895c072 100644 --- a/rm-main/src/transmission/action.rs +++ b/rm-main/src/transmission/action.rs @@ -127,23 +127,26 @@ pub async fn action_handler(ctx: app::Ctx, mut trans_rx: UnboundedReceiver { - if let Err(e) = ctx + match ctx .client .lock() .await .torrent_set_location(ids, new_directory.clone(), Option::from(true)) .await { - let error_title = "Failed to move torrent"; - let msg = "Failed to move torrent to new directory:\n\"".to_owned() - + new_directory.as_str() - + "\"\n" - + &e.to_string(); - let error_message = ErrorMessage { - title: error_title.to_string(), - message: msg, - }; - ctx.send_action(Action::Error(Box::new(error_message))); + Ok(_) => ctx.send_action(Action::TaskSuccess), + Err(e) => { + let error_title = "Failed to move torrent"; + let msg = "Failed to move torrent to new directory:\n\"".to_owned() + + new_directory.as_str() + + "\"\n" + + &e.to_string(); + let error_message = ErrorMessage { + title: error_title.to_string(), + message: msg, + }; + ctx.send_action(Action::Error(Box::new(error_message))); + } } } } diff --git a/rm-main/src/ui/tabs/torrents/task_manager.rs b/rm-main/src/ui/tabs/torrents/task_manager.rs index 09648f6..7f60c13 100644 --- a/rm-main/src/ui/tabs/torrents/task_manager.rs +++ b/rm-main/src/ui/tabs/torrents/task_manager.rs @@ -89,6 +89,7 @@ impl Component for TaskManager { _ => None, }, CurrentTask::MoveBar(move_bar) => match move_bar.handle_actions(action) { + Some(A::TaskPending(task)) => self.pending_task(task), Some(A::Quit) => self.cancel_task(), Some(A::Render) => Some(A::Render), _ => None, diff --git a/rm-main/src/ui/tabs/torrents/tasks/move_torrent.rs b/rm-main/src/ui/tabs/torrents/tasks/move_torrent.rs index a947ffc..f0cb237 100644 --- a/rm-main/src/ui/tabs/torrents/tasks/move_torrent.rs +++ b/rm-main/src/ui/tabs/torrents/tasks/move_torrent.rs @@ -1,6 +1,6 @@ use crossterm::event::{KeyCode, KeyEvent}; use ratatui::prelude::*; -use rm_shared::action::Action; +use rm_shared::{action::Action, status_task::StatusTask}; use transmission_rpc::types::Id; use crate::{ @@ -31,8 +31,8 @@ impl MoveBar { let new_location = self.input_mgr.text(); let torrents_to_move = self.torrents_to_move.clone(); self.ctx - .send_torrent_action(TorrentAction::Move(torrents_to_move, new_location)); - return Some(Action::Quit); + .send_torrent_action(TorrentAction::Move(torrents_to_move, new_location.clone())); + return Some(Action::TaskPending(StatusTask::Move(new_location))); } if input.code == KeyCode::Esc { diff --git a/rm-main/src/ui/tabs/torrents/tasks/status.rs b/rm-main/src/ui/tabs/torrents/tasks/status.rs index efc9da3..d07a830 100644 --- a/rm-main/src/ui/tabs/torrents/tasks/status.rs +++ b/rm-main/src/ui/tabs/torrents/tasks/status.rs @@ -40,6 +40,10 @@ impl Component for StatusBar { let display_name = format_display_name(&name); format!("Deleting {display_name}") } + StatusTask::Move(name) => { + let display_name = format_display_name(&name); + format!("Moving to {display_name}") + } }; let default_throbber = throbber_widgets_tui::Throbber::default() .label(status_text) @@ -61,6 +65,10 @@ impl Component for StatusBar { let display_name = format_display_name(&name); format!(" Error deleting {display_name}") } + StatusTask::Move(name) => { + let display_name = format_display_name(&name); + format!(" Error moving to {display_name}") + } }, CurrentTaskState::Success(_) => match &self.task { StatusTask::Add(name) => { @@ -71,6 +79,10 @@ impl Component for StatusBar { let display_name = format_display_name(&name); format!(" Deleted {display_name}") } + StatusTask::Move(name) => { + let display_name = format_display_name(&name); + format!(" Location moved to {display_name}") + } }, _ => return, }; diff --git a/rm-shared/src/status_task.rs b/rm-shared/src/status_task.rs index c550e11..79dae08 100644 --- a/rm-shared/src/status_task.rs +++ b/rm-shared/src/status_task.rs @@ -2,4 +2,5 @@ pub enum StatusTask { Add(String), Delete(String), + Move(String), }