diff --git a/rm-main/src/app.rs b/rm-main/src/app.rs index 0584837..c20230d 100644 --- a/rm-main/src/app.rs +++ b/rm-main/src/app.rs @@ -119,9 +119,7 @@ impl App { let tick_action = interval.tick(); tokio::select! { - _ = tick_action => { - self.ctx.action_tx.send(Action::Tick).unwrap(); - }, + _ = tick_action => self.tick(), event = tui_event => { if let Some(action) = event_to_action(self.mode, event.unwrap(), &self.ctx.config.keybindings.keymap) { @@ -185,4 +183,8 @@ impl App { _ => self.main_window.handle_update_action(action), } } + + fn tick(&mut self) { + self.main_window.tick(); + } } diff --git a/rm-main/src/ui/mod.rs b/rm-main/src/ui/mod.rs index 28d3c0b..6f215cd 100644 --- a/rm-main/src/ui/mod.rs +++ b/rm-main/src/ui/mod.rs @@ -49,7 +49,9 @@ impl Component for MainWindow { self.global_popup_manager.error_popup = Some(error_popup); self.ctx.send_action(A::Render); } - A::ShowHelp => {self.global_popup_manager.handle_actions(action);}, + A::ShowHelp => { + self.global_popup_manager.handle_actions(action); + } _ if self.global_popup_manager.needs_action() => { self.global_popup_manager.handle_actions(action); } @@ -76,6 +78,11 @@ impl Component for MainWindow { } } + fn tick(&mut self) { + self.search_tab.tick(); + self.torrents_tab.tick(); + } + fn render(&mut self, f: &mut Frame, rect: Rect) { let [top_bar, main_window] = Layout::vertical([Constraint::Length(1), Constraint::Percentage(100)]).areas(rect); diff --git a/rm-main/src/ui/tabs/search.rs b/rm-main/src/ui/tabs/search.rs index 085b565..0899600 100644 --- a/rm-main/src/ui/tabs/search.rs +++ b/rm-main/src/ui/tabs/search.rs @@ -26,15 +26,15 @@ use crate::{ use rm_shared::action::{Action, UpdateAction}; #[derive(Clone, Copy, PartialEq, Eq)] -enum SearchFocus { +enum SearchTabFocus { Search, List, } pub(crate) struct SearchTab { - search_focus: SearchFocus, + focus: SearchTabFocus, input: Input, - req_sender: UnboundedSender, + search_query_rx: UnboundedSender, table: GenericTable, // TODO: Change it to enum, and combine table with search_result_info search_result_info: SearchResultState, @@ -44,7 +44,7 @@ pub(crate) struct SearchTab { impl SearchTab { pub(crate) fn new(ctx: app::Ctx) -> Self { - let (tx, mut rx) = mpsc::unbounded_channel::(); + let (search_query_tx, mut search_query_rx) = mpsc::unbounded_channel::(); let table = GenericTable::new(vec![]); let search_result_info = SearchResultState::new(ctx.clone()); @@ -52,7 +52,7 @@ impl SearchTab { let ctx = ctx.clone(); async move { let magnetease = Magnetease::new(); - while let Some(search_phrase) = rx.recv().await { + while let Some(search_phrase) = search_query_rx.recv().await { ctx.send_update_action(UpdateAction::SearchStarted); let magnets = magnetease.search(&search_phrase).await.unwrap(); ctx.send_update_action(UpdateAction::SearchResults(magnets)); @@ -61,11 +61,11 @@ impl SearchTab { }); Self { - search_focus: SearchFocus::List, + focus: SearchTabFocus::List, input: Input::default(), table, search_result_info, - req_sender: tx, + search_query_rx: search_query_tx, currently_displaying_no: 0, ctx, } @@ -81,10 +81,10 @@ impl SearchTab { } fn change_focus(&mut self) { - if self.search_focus == SearchFocus::Search { - self.search_focus = SearchFocus::List; + if self.focus == SearchTabFocus::Search { + self.focus = SearchTabFocus::List; } else { - self.search_focus = SearchFocus::Search; + self.focus = SearchTabFocus::Search; } self.ctx.send_action(Action::Render); } @@ -102,13 +102,13 @@ impl SearchTab { match input.code { KeyCode::Enter => { - self.req_sender.send(self.input.to_string()).unwrap(); - self.search_focus = SearchFocus::List; + self.search_query_rx.send(self.input.to_string()).unwrap(); + self.focus = SearchTabFocus::List; self.ctx .send_update_action(UpdateAction::SwitchToNormalMode); } KeyCode::Esc => { - self.search_focus = SearchFocus::List; + self.focus = SearchTabFocus::List; self.ctx .send_update_action(UpdateAction::SwitchToNormalMode); } @@ -122,7 +122,7 @@ impl SearchTab { } fn start_search(&mut self) { - self.search_focus = SearchFocus::Search; + self.focus = SearchTabFocus::Search; self.ctx.send_update_action(UpdateAction::SwitchToInputMode); } @@ -174,9 +174,6 @@ 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(); - } _ => (), }; @@ -227,7 +224,7 @@ impl Component for SearchTab { .split(top_line)[1]; let input = { - if self.input.value().is_empty() && self.search_focus != SearchFocus::Search { + if self.input.value().is_empty() && self.focus != SearchTabFocus::Search { "press / to search" } else { self.input.value() @@ -235,7 +232,7 @@ impl Component for SearchTab { }; let search_style = { - if self.search_focus == SearchFocus::Search { + if self.focus == SearchTabFocus::Search { Style::default() .underlined() .fg(self.ctx.config.general.accent_color) diff --git a/rm-main/src/ui/tabs/torrents/tasks/status.rs b/rm-main/src/ui/tabs/torrents/tasks/status.rs index 0beeb73..67c4d7b 100644 --- a/rm-main/src/ui/tabs/torrents/tasks/status.rs +++ b/rm-main/src/ui/tabs/torrents/tasks/status.rs @@ -116,10 +116,6 @@ impl Component for StatusBar { fn handle_actions(&mut self, action: Action) -> ComponentAction { match action { - Action::Tick => { - self.tick(); - ComponentAction::Nothing - } Action::TaskSuccess => { self.task_status.set_success(); self.ctx.send_action(Action::Render); diff --git a/rm-shared/src/action.rs b/rm-shared/src/action.rs index ad5dc9f..443ba3f 100644 --- a/rm-shared/src/action.rs +++ b/rm-shared/src/action.rs @@ -11,7 +11,6 @@ pub enum Action { HardQuit, Quit, Close, - Tick, Render, Up, Down,