summaryrefslogtreecommitdiffstats
path: root/src/component/play.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/component/play.rs')
-rw-r--r--src/component/play.rs43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/component/play.rs b/src/component/play.rs
index 178be3c..512bc77 100644
--- a/src/component/play.rs
+++ b/src/component/play.rs
@@ -5,53 +5,62 @@ use zbus::Connection;
use crate::{
dbus::player::{PlaybackStatus, PlayerProxy},
- i3bar::{Block, Click},
+ i3bar::{Align, Block, Click, MinWidth},
Error,
};
-use super::{Button, Component, Update};
+use super::{Button, Component, Output, Update};
pub struct Play;
impl Component for Play {
- const NAME: &'static str = "play";
type Updater = Self;
type Colorer = ();
type Handler = Self;
+
+ fn initialize() -> Block {
+ Block {
+ name: Some("mpris-play".into()),
+ min_width: Some(MinWidth::Text("xx".to_string())),
+ align: Align::Center,
+ separator: Some(false),
+ separator_block_width: Some(0),
+ ..Default::default()
+ }
+ }
}
impl Update for Play {
- type Value = PlaybackStatus;
+ type Value = (char, Option<String>, Option<String>);
async fn listen(tx: Sender<Self::Value>, proxy: PlayerProxy<'_>) -> Result<(), Error> {
use futures_util::StreamExt;
+ let black = std::env::var("BASE16_COLOR_00_HEX").ok();
+ let cyan = std::env::var("BASE16_COLOR_0C_HEX").ok();
+ let yellow = std::env::var("BASE16_COLOR_0A_HEX").ok();
- tx.send(proxy.playback_status().await?).await?;
let mut stream = proxy.receive_playback_status_changed().await;
while let Some(signal) = stream.next().await {
if let Ok(value) = signal.get().await {
- tx.send(value).await?;
+ tx.send(match value {
+ PlaybackStatus::Playing => ('󰏤', black.clone(), cyan.clone()),
+ PlaybackStatus::Paused => ('󰐊', black.clone(), yellow.clone()),
+ PlaybackStatus::Stopped => ('󰐊', None, None),
+ })
+ .await?;
}
}
Ok(())
}
- async fn update(value: Self::Value, block: Arc<Mutex<Block>>) -> Result<bool, Error> {
- let black = std::env::var("BASE16_COLOR_00_HEX").ok();
- let cyan = std::env::var("BASE16_COLOR_0C_HEX").ok();
- let yellow = std::env::var("BASE16_COLOR_0A_HEX").ok();
-
- let (full_text, color, background) = match value {
- PlaybackStatus::Playing => (" 󰏤 ", black.clone(), cyan.clone()),
- PlaybackStatus::Paused => (" 󰐊 ", black.clone(), yellow.clone()),
- PlaybackStatus::Stopped => (" 󰐊 ", None, None),
- };
+ async fn update(value: Self::Value, block: Arc<Mutex<Block>>) -> Result<Output, Error> {
+ let (full_text, color, background) = value;
let mut block = block.lock().await;
block.full_text = full_text.into();
block.color = color;
block.background = background;
- Ok(true)
+ Ok(Output::Print)
}
}