diff --git a/src/player/mpris.rs b/src/player/mpris.rs index 0f40b4f..89a5506 100644 --- a/src/player/mpris.rs +++ b/src/player/mpris.rs @@ -11,6 +11,8 @@ use tokio::sync::mpsc::Sender; use super::Messages; +use super::ui::audio_bar_flash; + const ERROR: fdo::Error = fdo::Error::Failed(String::new()); /// The actual MPRIS player. @@ -188,6 +190,8 @@ impl PlayerInterface for Player { async fn set_volume(&self, volume: Volume) -> Result<()> { self.player.set_volume(volume as f32); + audio_bar_flash(); + Ok(()) } diff --git a/src/player/ui.rs b/src/player/ui.rs index 937caaa..ddd0664 100644 --- a/src/player/ui.rs +++ b/src/player/ui.rs @@ -48,6 +48,10 @@ lazy_static! { static ref VOLUME_TIMER: AtomicUsize = AtomicUsize::new(0); } +pub fn audio_bar_flash() { + VOLUME_TIMER.store(1, Ordering::Relaxed); +} + /// Represents an abstraction for drawing the actual lowfi window itself. /// /// The main purpose of this struct is just to add the fancy border, diff --git a/src/player/ui/input.rs b/src/player/ui/input.rs index 0a2a88c..bd4318d 100644 --- a/src/player/ui/input.rs +++ b/src/player/ui/input.rs @@ -1,15 +1,13 @@ //! Responsible for specifically recieving terminal input //! using [`crossterm`]. -use std::sync::atomic::Ordering; - use crossterm::event::{self, EventStream, KeyCode, KeyEventKind, KeyModifiers}; use futures::{FutureExt, StreamExt}; use tokio::sync::mpsc::Sender; use crate::player::Messages; -use super::VOLUME_TIMER; +use super::audio_bar_flash; /// Starts the listener to recieve input from the terminal for various events. pub async fn listen(sender: Sender) -> eyre::Result<()> { @@ -64,10 +62,10 @@ pub async fn listen(sender: Sender) -> eyre::Result<()> { _ => continue, }; - // If it's modifying the volume, then we'll set the `VOLUME_TIMER` to 1 + // If it's modifying the volume, then we'll call audio_bar_flash func // so that the UI thread will know that it should show the audio bar. if let Messages::ChangeVolume(_) = messages { - VOLUME_TIMER.store(1, Ordering::Relaxed); + audio_bar_flash(); } sender.send(messages).await?;