fix: show volume bar (mpris) (#59)

This commit is contained in:
danielwerg 2025-02-20 00:43:14 +03:00 committed by GitHub
parent 2b20bf7709
commit 67a4c4f0ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 5 deletions

View File

@ -11,6 +11,8 @@ use tokio::sync::mpsc::Sender;
use super::Messages; use super::Messages;
use super::ui::audio_bar_flash;
const ERROR: fdo::Error = fdo::Error::Failed(String::new()); const ERROR: fdo::Error = fdo::Error::Failed(String::new());
/// The actual MPRIS player. /// The actual MPRIS player.
@ -188,6 +190,8 @@ impl PlayerInterface for Player {
async fn set_volume(&self, volume: Volume) -> Result<()> { async fn set_volume(&self, volume: Volume) -> Result<()> {
self.player.set_volume(volume as f32); self.player.set_volume(volume as f32);
audio_bar_flash();
Ok(()) Ok(())
} }

View File

@ -48,6 +48,10 @@ lazy_static! {
static ref VOLUME_TIMER: AtomicUsize = AtomicUsize::new(0); 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. /// Represents an abstraction for drawing the actual lowfi window itself.
/// ///
/// The main purpose of this struct is just to add the fancy border, /// The main purpose of this struct is just to add the fancy border,

View File

@ -1,15 +1,13 @@
//! Responsible for specifically recieving terminal input //! Responsible for specifically recieving terminal input
//! using [`crossterm`]. //! using [`crossterm`].
use std::sync::atomic::Ordering;
use crossterm::event::{self, EventStream, KeyCode, KeyEventKind, KeyModifiers}; use crossterm::event::{self, EventStream, KeyCode, KeyEventKind, KeyModifiers};
use futures::{FutureExt, StreamExt}; use futures::{FutureExt, StreamExt};
use tokio::sync::mpsc::Sender; use tokio::sync::mpsc::Sender;
use crate::player::Messages; 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. /// Starts the listener to recieve input from the terminal for various events.
pub async fn listen(sender: Sender<Messages>) -> eyre::Result<()> { pub async fn listen(sender: Sender<Messages>) -> eyre::Result<()> {
@ -64,10 +62,10 @@ pub async fn listen(sender: Sender<Messages>) -> eyre::Result<()> {
_ => continue, _ => 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. // so that the UI thread will know that it should show the audio bar.
if let Messages::ChangeVolume(_) = messages { if let Messages::ChangeVolume(_) = messages {
VOLUME_TIMER.store(1, Ordering::Relaxed); audio_bar_flash();
} }
sender.send(messages).await?; sender.send(messages).await?;