Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add progress status for moving torrents #66

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions rm-main/src/transmission/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,26 @@ pub async fn action_handler(ctx: app::Ctx, mut trans_rx: UnboundedReceiver<Torre
sender.send(session_get).unwrap();
}
TorrentAction::Move(ids, new_directory) => {
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)));
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions rm-main/src/ui/tabs/torrents/task_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions rm-main/src/ui/tabs/torrents/tasks/move_torrent.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions rm-main/src/ui/tabs/torrents/tasks/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) => {
Expand All @@ -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,
};
Expand Down
1 change: 1 addition & 0 deletions rm-shared/src/status_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
pub enum StatusTask {
Add(String),
Delete(String),
Move(String),
}
Loading