mirror of
https://github.com/kristoferssolo/traxor.git
synced 2025-10-21 20:10:35 +00:00
feat(toggle): add toggle all
This commit is contained in:
parent
95a6d3483a
commit
61675c3422
@ -1,21 +1,42 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use transmission_rpc::types::{Torrent, TorrentAction, TorrentStatus};
|
use transmission_rpc::types::{Id, Torrent, TorrentAction, TorrentStatus};
|
||||||
|
|
||||||
use super::Torrents;
|
use super::Torrents;
|
||||||
|
|
||||||
impl Torrents {
|
impl Torrents {
|
||||||
pub async fn toggle(&mut self, torrent: &Torrent) -> transmission_rpc::types::Result<()> {
|
pub async fn toggle(&mut self, torrent: &Torrent) {
|
||||||
let id = torrent.id().ok_or_else(|| "ID not found")?;
|
let id = torrent.id().expect("ID not found");
|
||||||
let action = match torrent.status.ok_or_else(|| "Torrent status not found")? {
|
let action = match torrent.status.expect("Torrent status not found") {
|
||||||
TorrentStatus::Stopped => TorrentAction::StartNow,
|
TorrentStatus::Stopped => TorrentAction::StartNow,
|
||||||
_ => TorrentAction::Stop,
|
_ => TorrentAction::Stop,
|
||||||
};
|
};
|
||||||
self.client.torrent_action(action, vec![id]).await?;
|
self.client
|
||||||
Ok(())
|
.torrent_action(action, vec![id])
|
||||||
|
.await
|
||||||
|
.expect("Error toggling torrent");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn toggle_all(&mut self) -> transmission_rpc::types::Result<()> {
|
pub async fn toggle_all(&mut self) {
|
||||||
todo!()
|
let torrents: Vec<(Id, TorrentAction)> = self
|
||||||
|
.torrents()
|
||||||
|
.iter()
|
||||||
|
.map(|torrent| {
|
||||||
|
(
|
||||||
|
torrent.id().unwrap(),
|
||||||
|
match torrent.status {
|
||||||
|
Some(TorrentStatus::Stopped) => TorrentAction::StartNow,
|
||||||
|
_ => TorrentAction::Stop,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
for (id, action) in torrents {
|
||||||
|
self.client
|
||||||
|
.torrent_action(action, vec![id])
|
||||||
|
.await
|
||||||
|
.expect("Error toggling torrent");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_dir(&mut self) -> Result<()> {
|
pub fn move_dir(&mut self) -> Result<()> {
|
||||||
|
|||||||
@ -118,11 +118,10 @@ impl<'a> App<'a> {
|
|||||||
self.show_popup = true;
|
self.show_popup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn toggle_torrent(&mut self) -> transmission_rpc::types::Result<()> {
|
pub async fn toggle_torrent(&mut self) {
|
||||||
let torrent = self.selected().ok_or_else(|| "Torrent not found")?;
|
let torrent = self.selected().expect("Torrent not found");
|
||||||
self.torrents.toggle(&torrent.clone()).await?;
|
self.torrents.toggle(&torrent.clone()).await;
|
||||||
self.close_popup();
|
self.close_popup();
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn selected(&self) -> Option<&Torrent> {
|
fn selected(&self) -> Option<&Torrent> {
|
||||||
|
|||||||
@ -30,7 +30,11 @@ pub async fn handle_key_events(key_event: KeyEvent, app: &mut App<'_>) -> Result
|
|||||||
KeyCode::Char('4') => app.switch_tab(3),
|
KeyCode::Char('4') => app.switch_tab(3),
|
||||||
KeyCode::Char('t') | KeyCode::Enter | KeyCode::Menu => {
|
KeyCode::Char('t') | KeyCode::Enter | KeyCode::Menu => {
|
||||||
app.toggle_popup();
|
app.toggle_popup();
|
||||||
app.toggle_torrent().await.unwrap();
|
app.toggle_torrent().await;
|
||||||
|
}
|
||||||
|
KeyCode::Char('a') => {
|
||||||
|
app.toggle_popup();
|
||||||
|
app.torrents.toggle_all().await;
|
||||||
}
|
}
|
||||||
// Other handlers you could add here.
|
// Other handlers you could add here.
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user