Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski committed Jun 30, 2024
2 parents a9f1655 + 8cfd72f commit 2179431
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 11 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ crossterm = { version = "0.27", features = ["event-stream", "serde"] }
ratatui = { version = "0.26", features = ["serde"] }
tui-input = "0.8"
tui-tree-widget = "0.20"
throbber-widgets-tui = "0.5.0"

# Config for 'cargo dist'
[workspace.metadata.dist]
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ or with Nix:
nix run .
```

or with Brew:
```bash
brew install intuis/tap/rustmission
```

## Usage

Launch Rustmission in your terminal to initialize the configuration and make adjustments as needed. Subsequently, run Rustmission again. For a list of keybindings, press '?'.
Expand Down
5 changes: 4 additions & 1 deletion rm-config/defaults/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ url = "http://CHANGE_ME:9091/transmission/rpc" # REQUIRED!
# username = "CHANGE_ME"
# password = "CHANGE_ME"


# Refresh timings (in seconds)
torrents_refresh = 5
stats_refresh = 10
free_space_refresh = 10
6 changes: 6 additions & 0 deletions rm-config/src/main_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ pub struct Connection {
pub username: Option<String>,
pub password: Option<String>,
pub url: Url,
#[serde(default)]
pub torrents_refresh: u64,
#[serde(default)]
pub stats_refresh: u64,
#[serde(default)]
pub free_space_refresh: u64,
}

impl MainConfig {
Expand Down
2 changes: 2 additions & 0 deletions rm-main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ crossterm.workspace = true
ratatui.workspace = true
tui-input.workspace = true
tui-tree-widget.workspace = true
throbber-widgets-tui.workspace = true

6 changes: 6 additions & 0 deletions rm-main/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,17 @@ impl App {
}

async fn main_loop(&mut self, tui: &mut Tui) -> Result<()> {
let mut interval = tokio::time::interval(tokio::time::Duration::from_millis(250));
loop {
let tui_event = tui.next();
let action = self.action_rx.recv();
let tick_action = interval.tick();

tokio::select! {
_ = tick_action => {
self.ctx.action_tx.send(Action::Tick).unwrap();
},

event = tui_event => {
if let Some(action) = event_to_action(self.mode, event.unwrap(), &self.ctx.config.keybindings.keymap) {
if let Some(action) = self.update(action).await {
Expand Down
9 changes: 6 additions & 3 deletions rm-main/src/transmission/fetchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub async fn stats(ctx: app::Ctx, stats: Arc<Mutex<Option<SessionStats>>>) {
.arguments;
*stats.lock().unwrap() = Some(new_stats);
ctx.send_action(Action::Render);
tokio::time::sleep(Duration::from_secs(5)).await;
tokio::time::sleep(Duration::from_secs(ctx.config.connection.stats_refresh)).await;
}
}

Expand All @@ -50,7 +50,10 @@ pub async fn free_space(ctx: app::Ctx, free_space: Arc<Mutex<Option<FreeSpace>>>
.arguments;
*free_space.lock().unwrap() = Some(new_free_space);
ctx.send_action(Action::Render);
tokio::time::sleep(Duration::from_secs(10)).await;
tokio::time::sleep(Duration::from_secs(
ctx.config.connection.free_space_refresh,
))
.await;
}
}

Expand Down Expand Up @@ -85,6 +88,6 @@ pub async fn torrents(ctx: app::Ctx, table_manager: Arc<Mutex<TableManager>>) {
.set_new_rows(new_torrents.iter().map(RustmissionTorrent::from).collect());
}
ctx.send_action(Action::Render);
tokio::time::sleep(Duration::from_secs(5)).await;
tokio::time::sleep(Duration::from_secs(ctx.config.connection.torrents_refresh)).await;
}
}
3 changes: 3 additions & 0 deletions rm-main/src/ui/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ pub trait Component {
None
}
fn render(&mut self, _f: &mut Frame, _rect: Rect) {}
fn tick(&mut self) -> Option<Action> {
None
}
}
41 changes: 34 additions & 7 deletions rm-main/src/ui/tabs/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use ratatui::{
prelude::*,
widgets::{Cell, Paragraph, Row, Table},
};
use throbber_widgets_tui::ThrobberState;
use tokio::sync::mpsc::{self, UnboundedSender};
use tui_input::Input;

Expand Down Expand Up @@ -53,7 +54,10 @@ impl SearchTab {
tokio::task::spawn(async move {
let magnetease = Magnetease::new();
while let Some(search_phrase) = rx.recv().await {
search_result_info_clone.lock().unwrap().searching();
search_result_info_clone
.lock()
.unwrap()
.searching(Arc::new(Mutex::new(ThrobberState::default())));
ctx_clone.send_action(Action::Render);
let res = magnetease.search(&search_phrase).await;
if res.is_empty() {
Expand Down Expand Up @@ -193,11 +197,17 @@ impl Component for SearchTab {
A::Home => self.scroll_to_home(),
A::End => self.scroll_to_end(),
A::Confirm => self.add_torrent(),
A::Tick => self.tick(),

_ => None,
}
}

fn tick(&mut self) -> Option<Action> {
self.search_result_info.lock().unwrap().tick();
Some(Action::Render)
}

fn render(&mut self, f: &mut Frame, rect: Rect) {
let [top_line, rest, bottom_line] = Layout::vertical([
Constraint::Length(1),
Expand Down Expand Up @@ -284,11 +294,11 @@ impl Component for SearchTab {
}
}

#[derive(Clone, Copy)]
#[derive(Clone)]
enum SearchResultState {
Nothing,
NoResults,
Searching,
Searching(Arc<Mutex<ThrobberState>>),
Found(usize),
}

Expand All @@ -297,8 +307,8 @@ impl SearchResultState {
Self::Nothing
}

fn searching(&mut self) {
*self = Self::Searching;
fn searching(&mut self, state: Arc<Mutex<ThrobberState>>) {
*self = Self::Searching(state);
}

fn not_found(&mut self) {
Expand All @@ -314,8 +324,15 @@ impl Component for SearchResultState {
fn render(&mut self, f: &mut Frame, rect: Rect) {
match self {
SearchResultState::Nothing => return,
SearchResultState::Searching => {
f.render_widget("󱗼 Searching...", rect);
SearchResultState::Searching(state) => {
let default_throbber = throbber_widgets_tui::Throbber::default()
.label("Searching...")
.style(ratatui::style::Style::default().fg(ratatui::style::Color::Yellow));
f.render_stateful_widget(
default_throbber.clone(),
rect,
&mut state.lock().unwrap(),
);
}
SearchResultState::NoResults => {
let mut line = Line::default();
Expand All @@ -333,4 +350,14 @@ impl Component for SearchResultState {
}
}
}

fn tick(&mut self) -> Option<Action> {
match self {
SearchResultState::Searching(state) => {
state.lock().unwrap().calc_next();
Some(Action::Render)
}
_ => None,
}
}
}
1 change: 1 addition & 0 deletions rm-shared/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub enum Action {
HardQuit,
Quit,
Close,
Tick,
Render,
Up,
Down,
Expand Down

0 comments on commit 2179431

Please sign in to comment.