mirror of
https://github.com/kristoferssolo/traxor.git
synced 2025-10-21 20:10:35 +00:00
feat: add pause/start all torrents
This commit is contained in:
parent
61675c3422
commit
c3f2b9113a
@ -18,7 +18,7 @@ impl Torrents {
|
|||||||
|
|
||||||
pub async fn toggle_all(&mut self) {
|
pub async fn toggle_all(&mut self) {
|
||||||
let torrents: Vec<(Id, TorrentAction)> = self
|
let torrents: Vec<(Id, TorrentAction)> = self
|
||||||
.torrents()
|
.torrents
|
||||||
.iter()
|
.iter()
|
||||||
.map(|torrent| {
|
.map(|torrent| {
|
||||||
(
|
(
|
||||||
@ -39,6 +39,18 @@ impl Torrents {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn start_all(&mut self) {
|
||||||
|
self.action_all(TorrentAction::StartNow)
|
||||||
|
.await
|
||||||
|
.expect("Error starting all torrents");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn stop_all(&mut self) {
|
||||||
|
self.action_all(TorrentAction::Stop)
|
||||||
|
.await
|
||||||
|
.expect("Error stopping all torrents");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn move_dir(&mut self) -> Result<()> {
|
pub fn move_dir(&mut self) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@ -50,4 +62,15 @@ impl Torrents {
|
|||||||
pub fn rename(&mut self) -> Result<()> {
|
pub fn rename(&mut self) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn action_all(&mut self, action: TorrentAction) -> transmission_rpc::types::Result<()> {
|
||||||
|
let ids = self
|
||||||
|
.torrents
|
||||||
|
.iter()
|
||||||
|
.filter_map(|torrent| torrent.id())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
self.client.torrent_action(action, ids).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -126,7 +126,7 @@ impl<'a> App<'a> {
|
|||||||
|
|
||||||
fn selected(&self) -> Option<&Torrent> {
|
fn selected(&self) -> Option<&Torrent> {
|
||||||
let idx = self.state.selected()?;
|
let idx = self.state.selected()?;
|
||||||
let torrent = self.torrents.torrents().get(idx)?;
|
let torrent = self.torrents.torrents.get(idx)?;
|
||||||
Some(torrent)
|
Some(torrent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,9 +12,9 @@ use url::Url;
|
|||||||
pub struct Torrents {
|
pub struct Torrents {
|
||||||
/// Constructs a new instance of [`Torrents`].
|
/// Constructs a new instance of [`Torrents`].
|
||||||
pub client: TransClient,
|
pub client: TransClient,
|
||||||
torrents: Vec<Torrent>,
|
pub torrents: Vec<Torrent>,
|
||||||
ids: Option<Vec<Id>>,
|
pub ids: Option<Vec<Id>>,
|
||||||
fields: Option<Vec<TorrentGetField>>,
|
pub fields: Option<Vec<TorrentGetField>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Torrents {
|
impl Torrents {
|
||||||
@ -57,11 +57,6 @@ impl Torrents {
|
|||||||
.torrents;
|
.torrents;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns [`Vec`] of [`Torrent`] as reference.
|
|
||||||
pub fn torrents(&self) -> &Vec<Torrent> {
|
|
||||||
&self.torrents
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Torrents {
|
impl Debug for Torrents {
|
||||||
|
|||||||
@ -6,22 +6,16 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
|||||||
pub async fn handle_key_events(key_event: KeyEvent, app: &mut App<'_>) -> Result<()> {
|
pub async fn handle_key_events(key_event: KeyEvent, app: &mut App<'_>) -> Result<()> {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
// Exit application on `ESC` or `q`
|
// Exit application on `ESC` or `q`
|
||||||
KeyCode::Esc | KeyCode::Char('q') => {
|
KeyCode::Esc | KeyCode::Char('q') => app.quit(),
|
||||||
app.quit();
|
|
||||||
}
|
|
||||||
// Exit application on `Ctrl-C`
|
// Exit application on `Ctrl-C`
|
||||||
KeyCode::Char('c') | KeyCode::Char('C') => {
|
KeyCode::Char('c') | KeyCode::Char('C') => {
|
||||||
if key_event.modifiers == KeyModifiers::CONTROL {
|
if key_event.modifiers == KeyModifiers::CONTROL {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('l') | KeyCode::Right => {
|
KeyCode::Char('l') | KeyCode::Right => app.next_tab(),
|
||||||
app.next_tab();
|
KeyCode::Char('h') | KeyCode::Left => app.prev_tab(),
|
||||||
}
|
|
||||||
KeyCode::Char('h') | KeyCode::Left => {
|
|
||||||
app.prev_tab();
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyCode::Char('j') | KeyCode::Down => app.next(),
|
KeyCode::Char('j') | KeyCode::Down => app.next(),
|
||||||
KeyCode::Char('k') | KeyCode::Up => app.previous(),
|
KeyCode::Char('k') | KeyCode::Up => app.previous(),
|
||||||
KeyCode::Char('1') => app.switch_tab(0),
|
KeyCode::Char('1') => app.switch_tab(0),
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use crate::app::{utils::Wrapper, App, Tab};
|
|||||||
|
|
||||||
pub fn render_table<'a>(app: &mut App, tab: Tab) -> Table<'a> {
|
pub fn render_table<'a>(app: &mut App, tab: Tab) -> Table<'a> {
|
||||||
let fields = tab.fields();
|
let fields = tab.fields();
|
||||||
let torrents = app.torrents.set_fields(None).torrents();
|
let torrents = &app.torrents.set_fields(None).torrents;
|
||||||
|
|
||||||
let rows: Vec<Row<'_>> = torrents
|
let rows: Vec<Row<'_>> = torrents
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user