From 3805929479b58eb53bd86244abe676c9b4c1def2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Mon, 31 Jan 2022 14:08:02 +0100 Subject: [PATCH] volume 0 when muted --- src/utils/volume.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/utils/volume.rs b/src/utils/volume.rs index 5c6d3e1..472d5cd 100644 --- a/src/utils/volume.rs +++ b/src/utils/volume.rs @@ -20,23 +20,25 @@ pub async fn get_volume() -> ThreadsData { .get_playback_volume(selem_chan_id) .expect("Failed to get raw_volume"); + let muted = selem + .get_playback_switch(selem_chan_id) + .expect("Failed to get playback state") + == 0; + let range = max - min; - let vol = if range == 0 { + let vol = if muted || range == 0 { 0 } else { raw_volume -= min; ((raw_volume as f64 / range as f64) * 100.) as u64 }; - let muted = selem - .get_playback_switch(selem_chan_id) - .expect("Failed to get playback state"); - let icon = match muted { - 0 => &CONFIG.volume.icon_muted, - _ => if vol < 50 { &CONFIG.volume.icon_low } else { &CONFIG.volume.icon_high } + true => &CONFIG.volume.icon_muted, + false => if vol < 50 { &CONFIG.volume.icon_low } else { &CONFIG.volume.icon_high } }; - let data = format!(" {} {}% {}", icon, vol, CONFIG.seperator); + + let data = format!(" {} {:>2}% {}", icon, vol, CONFIG.seperator); ThreadsData::Sound(data) }