diff --git a/src/download.rs b/src/download.rs index c1cad15..e578082 100644 --- a/src/download.rs +++ b/src/download.rs @@ -88,7 +88,7 @@ impl Handle { Ok(queued) => Output::Queued(queued), Err(_) => { PROGRESS.store(0, atomic::Ordering::Relaxed); - Output::Loading(&PROGRESS) + Output::Loading(progress()) } } } diff --git a/src/player.rs b/src/player.rs index 400cef4..527b5ad 100644 --- a/src/player.rs +++ b/src/player.rs @@ -21,7 +21,6 @@ pub enum Current { } pub struct Player { - ui: ui::Handle, downloader: download::Handle, volume: PersistentVolume, bookmarks: Bookmarks, @@ -29,6 +28,7 @@ pub struct Player { rx: Receiver, broadcast: broadcast::Sender, current: Current, + _ui: ui::Handle, _tx: Sender, _stream: rodio::OutputStream, } @@ -84,12 +84,12 @@ impl Player { Ok(Self { current, downloader, - ui, broadcast: utx, rx, sink, bookmarks, volume, + _ui: ui, _stream: stream, _tx: tx, }) diff --git a/src/ui.rs b/src/ui.rs index 9daccc4..09d3679 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -8,6 +8,7 @@ use crate::{ use tokio::{ sync::{broadcast, mpsc::Sender}, task::JoinHandle, + time::Instant, }; mod components; mod environment; @@ -39,6 +40,7 @@ pub struct State { pub sink: Arc, pub current: Current, pub bookmarked: bool, + timer: Option, width: usize, } @@ -50,6 +52,7 @@ impl State { sink, current, bookmarked: false, + timer: None, } } } @@ -90,7 +93,7 @@ impl Handle { let mut window = Window::new(state.width, params.borderless); loop { - interface::draw(&state, &mut window, params).await?; + interface::draw(&mut state, &mut window, params).await?; if let Ok(message) = rx.try_recv() { match message { diff --git a/src/ui/interface.rs b/src/ui/interface.rs index d13965d..60ff22d 100644 --- a/src/ui/interface.rs +++ b/src/ui/interface.rs @@ -28,28 +28,23 @@ impl From<&Args> for Params { /// The code for the terminal interface itself. /// /// * `minimalist` - All this does is hide the bottom control bar. -pub async fn draw(state: &ui::State, window: &mut Window, params: Params) -> super::Result<()> { +pub async fn draw(state: &mut ui::State, window: &mut Window, params: Params) -> super::Result<()> { let action = components::action(&state, state.width); let volume = state.sink.volume(); let percentage = format!("{}%", (volume * 100.0).round().abs()); - // let timer = VOLUME_TIMER.load(Ordering::Relaxed); - // let middle = match timer { - let middle = components::progress_bar(&state, state.width - 16); - // _ => components::audio_bar(volume, &percentage, width - 17), - // }; - - // if timer > 0 && timer <= AUDIO_BAR_DURATION { - // // We'll keep increasing the timer until it eventually hits `AUDIO_BAR_DURATION`. - // VOLUME_TIMER.fetch_add(1, Ordering::Relaxed); - // } else { - // // If enough time has passed, we'll reset it back to 0. - // VOLUME_TIMER.store(0, Ordering::Relaxed); - // } + let middle = match state.timer { + Some(timer) => { + if timer.elapsed() > Duration::from_secs(3) { + state.timer = None; + }; + components::progress_bar(&state, state.width - 16) + } + None => components::audio_bar(state.width - 17, volume, &percentage), + }; let controls = components::controls(state.width); - let menu = match (params.minimalist, &state.current) { (true, _) => vec![action, middle], // (false, Some(x)) => vec![x.path.clone(), action, middle, controls],