diff --git a/rm-main/src/ui/tabs/torrents/task_manager.rs b/rm-main/src/ui/tabs/torrents/task_manager.rs index a697ad6..55e05ab 100644 --- a/rm-main/src/ui/tabs/torrents/task_manager.rs +++ b/rm-main/src/ui/tabs/torrents/task_manager.rs @@ -3,7 +3,11 @@ use std::sync::{Arc, Mutex}; use ratatui::prelude::*; use throbber_widgets_tui::ThrobberState; -use crate::{action::Action, app, ui::components::Component}; +use crate::{ + action::Action, + app::{self}, + ui::components::Component, +}; use super::{ tasks::{ @@ -40,6 +44,24 @@ pub enum CurrentTask { Status(StatusBar), } +impl CurrentTask { + fn tick(&mut self) -> Option { + if let Self::Status(status_bar) = self { + // if let CurrentTaskState::Success(start) = status_bar.task_status { + // let expiration_duration = tokio::time::Duration::from_secs(5); + // if start.elapsed() > expiration_duration { + // *self = CurrentTask::Default(DefaultBar::new(ctx)); + // return Some(Action::Render); + // } else { + // return status_bar.tick(); + // } + // } + return status_bar.tick(); + } + None + } +} + impl Component for TaskManager { #[must_use] fn handle_actions(&mut self, action: Action) -> Option { @@ -105,19 +127,7 @@ impl Component for TaskManager { } fn tick(&mut self) -> Option { - if let CurrentTask::Status(status_bar) = &mut self.current_task { - if let CurrentTaskState::Success(start) = status_bar.task_status { - let expiration_duration = tokio::time::Duration::from_secs(5); - println!("{:?}, {:?}", start, expiration_duration); - if start.elapsed() > expiration_duration { - self.current_task = CurrentTask::Default(DefaultBar::new(self.ctx.clone())); - return Some(Action::Render); - } else { - return status_bar.tick(); - } - } - } - None + self.current_task.tick() } } diff --git a/rm-main/src/ui/tabs/torrents/tasks/status.rs b/rm-main/src/ui/tabs/torrents/tasks/status.rs index c528da5..4af94a5 100644 --- a/rm-main/src/ui/tabs/torrents/tasks/status.rs +++ b/rm-main/src/ui/tabs/torrents/tasks/status.rs @@ -4,7 +4,7 @@ use crate::{action::Action, ui::components::Component}; use ratatui::{prelude::*, widgets::Paragraph}; use throbber_widgets_tui::ThrobberState; -use tokio::time::Instant; +use tokio::time::{self, Instant}; pub struct StatusBar { task: StatusTask, @@ -95,11 +95,11 @@ impl Component for StatusBar { match action { Action::Tick => self.tick(), Action::TaskSuccess => { - self.task_status.success(tokio::time::Instant::now()); + self.task_status.set_success(time::Instant::now()); Some(Action::Render) } Action::Error(_) => { - self.task_status.failure(); + self.task_status.set_failure(); Some(Action::Render) } _ => Some(action), @@ -113,8 +113,8 @@ impl Component for StatusBar { Some(Action::Render) } CurrentTaskState::Success(start) => { - let expiration_duration = tokio::time::Duration::from_secs(5); - if start.elapsed() > expiration_duration { + let expiration_duration = time::Duration::from_secs(5); + if start.elapsed() >= expiration_duration { return Some(Action::Quit); } None @@ -138,11 +138,11 @@ pub enum CurrentTaskState { } impl CurrentTaskState { - fn failure(&mut self) { + fn set_failure(&mut self) { *self = Self::Failure; } - fn success(&mut self, start: Instant) { + fn set_success(&mut self, start: Instant) { *self = Self::Success(start); } }