mirror of
https://github.com/kristoferssolo/traxor.git
synced 2025-10-21 20:10:35 +00:00
refactor(toggle): add toggle method to Torrents
This commit is contained in:
parent
c199325d50
commit
95a6d3483a
32
src/app/command.rs
Normal file
32
src/app/command.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use anyhow::Result;
|
||||
use transmission_rpc::types::{Torrent, TorrentAction, TorrentStatus};
|
||||
|
||||
use super::Torrents;
|
||||
|
||||
impl Torrents {
|
||||
pub async fn toggle(&mut self, torrent: &Torrent) -> transmission_rpc::types::Result<()> {
|
||||
let id = torrent.id().ok_or_else(|| "ID not found")?;
|
||||
let action = match torrent.status.ok_or_else(|| "Torrent status not found")? {
|
||||
TorrentStatus::Stopped => TorrentAction::StartNow,
|
||||
_ => TorrentAction::Stop,
|
||||
};
|
||||
self.client.torrent_action(action, vec![id]).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn toggle_all(&mut self) -> transmission_rpc::types::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn move_dir(&mut self) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn delete(&mut self) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn rename(&mut self) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,8 @@ mod torrent;
|
||||
pub mod utils;
|
||||
|
||||
use ratatui::widgets::TableState;
|
||||
use transmission_rpc::types::{Result, Torrent, TorrentAction, TorrentStatus};
|
||||
use transmission_rpc::types::Torrent;
|
||||
mod command;
|
||||
|
||||
pub use self::{tab::Tab, torrent::Torrents};
|
||||
|
||||
@ -117,17 +118,9 @@ impl<'a> App<'a> {
|
||||
self.show_popup = true;
|
||||
}
|
||||
|
||||
pub async fn toggle_torrent(&mut self) -> Result<()> {
|
||||
pub async fn toggle_torrent(&mut self) -> transmission_rpc::types::Result<()> {
|
||||
let torrent = self.selected().ok_or_else(|| "Torrent not found")?;
|
||||
let id = torrent.id().ok_or_else(|| "ID not found")?;
|
||||
let action = match torrent.status.ok_or_else(|| "Torrent status not found")? {
|
||||
TorrentStatus::Stopped => TorrentAction::StartNow,
|
||||
_ => TorrentAction::Stop,
|
||||
};
|
||||
self.torrents
|
||||
.client
|
||||
.torrent_action(action, vec![id])
|
||||
.await?;
|
||||
self.torrents.toggle(&torrent.clone()).await?;
|
||||
self.close_popup();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user