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) }