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: visually handle torrents with errors #71

Merged
merged 1 commit into from
Jul 24, 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
2 changes: 2 additions & 0 deletions rm-main/src/transmission/fetchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub async fn torrents(ctx: app::Ctx) {
TorrentGetField::ActivityDate,
TorrentGetField::AddedDate,
TorrentGetField::PeersConnected,
TorrentGetField::Error,
TorrentGetField::ErrorString,
];
let (torrents_tx, torrents_rx) = oneshot::channel();
ctx.send_torrent_action(TorrentAction::GetTorrents(fields, torrents_tx));
Expand Down
66 changes: 45 additions & 21 deletions rm-main/src/ui/tabs/torrents/rustmission_torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rm_shared::{
bytes_to_human_format, download_speed_format, seconds_to_human_format, upload_speed_format,
},
};
use transmission_rpc::types::{Id, Torrent, TorrentStatus};
use transmission_rpc::types::{ErrorType, Id, Torrent, TorrentStatus};

#[derive(Clone)]
pub struct RustmissionTorrent {
Expand All @@ -29,6 +29,7 @@ pub struct RustmissionTorrent {
pub activity_date: NaiveDateTime,
pub added_date: NaiveDateTime,
pub peers_connected: i64,
pub error: Option<String>,
}

impl RustmissionTorrent {
Expand Down Expand Up @@ -62,7 +63,7 @@ impl RustmissionTorrent {
if *header == Header::Name {
cells.push(torrent_name_line.clone())
} else {
cells.push(self.header_to_line(*header))
cells.push(self.header_to_line(*header).style(self.style))
}
}

Expand All @@ -88,21 +89,27 @@ impl RustmissionTorrent {
Header::ActivityDate => time_to_line(self.activity_date),
Header::AddedDate => time_to_line(self.added_date),
Header::PeersConnected => Line::from(self.peers_connected.to_string()),
Header::SmallStatus => match self.status() {
TorrentStatus::Stopped => Line::from("󰏤"),
TorrentStatus::QueuedToVerify => Line::from("󱥸"),
TorrentStatus::Verifying => Line::from("󰑓"),
TorrentStatus::QueuedToDownload => Line::from("󱥸"),
TorrentStatus::QueuedToSeed => Line::from("󱥸"),
TorrentStatus::Seeding => {
if !self.upload_speed.is_empty() {
Line::from("")
} else {
Line::from("󰄬")
Header::SmallStatus => {
if self.error.is_some() {
return Line::from("");
}

match self.status() {
TorrentStatus::Stopped => Line::from("󰏤"),
TorrentStatus::QueuedToVerify => Line::from("󱥸"),
TorrentStatus::Verifying => Line::from("󰑓"),
TorrentStatus::QueuedToDownload => Line::from("󱥸"),
TorrentStatus::QueuedToSeed => Line::from("󱥸"),
TorrentStatus::Seeding => {
if !self.upload_speed.is_empty() {
Line::from("")
} else {
Line::from("󰄬")
}
}
TorrentStatus::Downloading => Line::from(""),
}
TorrentStatus::Downloading => Line::from(""),
},
}
}
}

Expand All @@ -111,7 +118,9 @@ impl RustmissionTorrent {
}

pub fn update_status(&mut self, new_status: TorrentStatus) {
if new_status == TorrentStatus::Stopped {
if self.error.is_some() {
self.style = Style::default().red().italic();
} else if new_status == TorrentStatus::Stopped {
self.style = Style::default().dark_gray().italic();
} else {
self.style = Style::default();
Expand Down Expand Up @@ -152,11 +161,6 @@ impl From<Torrent> for RustmissionTorrent {

let status = t.status.expect("field requested");

let style = match status {
TorrentStatus::Stopped => Style::default().dark_gray().italic(),
_ => Style::default(),
};

let download_dir = t.download_dir.clone().expect("field requested");

let uploaded_ever = bytes_to_human_format(t.uploaded_ever.expect("field requested"));
Expand All @@ -182,6 +186,25 @@ impl From<Torrent> for RustmissionTorrent {

let peers_connected = t.peers_connected.expect("field requested");

let error = {
if t.error.expect("field requested") != ErrorType::Ok {
Some(t.error_string.expect("field requested"))
} else {
None
}
};

let style = {
if error.is_some() {
Style::default().red().italic()
} else {
match status {
TorrentStatus::Stopped => Style::default().dark_gray().italic(),
_ => Style::default(),
}
}
};

Self {
torrent_name,
size_when_done,
Expand All @@ -198,6 +221,7 @@ impl From<Torrent> for RustmissionTorrent {
activity_date,
added_date,
peers_connected,
error,
}
}
}
Expand Down
Loading