summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2024-07-20 02:30:53 -0500
committerToby Vincent <tobyv@tobyvin.dev>2024-07-20 02:30:53 -0500
commitbab037ad907a4948799ecd545986fa2d4c709c7a (patch)
tree0eca40be62451b24e8592df34fb194149c89b428
parent9680a9375f3faa3ae3f6f4b78957de0ea2383dae (diff)
fix: print spacer when volume fails
-rw-r--r--src/bin/mpris-volume.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/bin/mpris-volume.rs b/src/bin/mpris-volume.rs
index c6a457e..cf123d9 100644
--- a/src/bin/mpris-volume.rs
+++ b/src/bin/mpris-volume.rs
@@ -23,16 +23,16 @@ impl Component for Volume {
}
impl Update for Volume {
- type Value = f64;
+ type Value = Option<f64>;
async fn listen(tx: Sender<Self::Value>, proxy: PlayerProxy<'_>) -> Result<(), Error> {
use futures_util::StreamExt;
- tx.send(proxy.volume().await?).await?;
+ tx.send(proxy.volume().await.ok()).await?;
let mut stream = proxy.receive_volume_changed().await;
while let Some(signal) = stream.next().await {
if let Ok(value) = signal.get().await {
- tx.send(value).await?;
+ tx.send(Some(value)).await?;
}
}
Ok(())
@@ -40,11 +40,13 @@ impl Update for Volume {
async fn update(value: Self::Value, block: Arc<Mutex<Block>>) -> Result<bool, Error> {
let mut block = block.lock().await;
- block.full_text = match (value * 100_f64) as u32 {
- v @ 66.. => format!(" 󰕾 {v}% "),
- v @ 33.. => format!(" 󰖀 {v}% "),
- v @ 0.. => format!(" 󰕿 {v}% "),
+ block.full_text = match value.map(|v| (v * 100_f64) as u32) {
+ Some(v @ 66..) => format!(" 󰕾 {v}% "),
+ Some(v @ 33..) => format!(" 󰖀 {v}% "),
+ Some(v @ 0..) => format!(" 󰕿 {v}% "),
+ None => " ".to_string(),
};
+
Ok(true)
}
}