Skip to content

Commit

Permalink
Add UI for mute
Browse files Browse the repository at this point in the history
Signed-off-by: Bailey Kasin <[email protected]>
  • Loading branch information
Bailey Kasin committed Sep 22, 2023
1 parent 1bfa73b commit 8b7d9a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion spotify_player/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ fn handle_global_command(
Command::Mute => {
if let Some(ref playback) = state.player.read().buffered_playback {
if let Some(volume) = state.player.read().mute_state {
client_pub.send(ClientRequest::Player(PlayerRequest::ToggleMute(0)))?;
client_pub.send(ClientRequest::Player(PlayerRequest::Volume(volume as u8)))?;
client_pub.send(ClientRequest::Player(PlayerRequest::ToggleMute(0)))?;
} else if let Some(volume) = playback.volume {
client_pub.send(ClientRequest::Player(PlayerRequest::ToggleMute(volume)))?;
client_pub.send(ClientRequest::Player(PlayerRequest::Volume(0)))?;
Expand Down
21 changes: 18 additions & 3 deletions spotify_player/src/ui/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ pub fn render_playback_window(
};

if let Some(ref playback) = player.buffered_playback {
render_playback_text(frame, state, ui, metadata_rect, track, playback);
render_playback_text(
frame,
state,
ui,
metadata_rect,
track,
playback,
player.mute_state,
);
}

let progress = std::cmp::min(
Expand Down Expand Up @@ -133,6 +141,7 @@ fn render_playback_text(
rect: Rect,
track: &rspotify_model::FullTrack,
playback: &SimplifiedPlayback,
mute_state: Option<u32>,
) {
// Construct a "styled" text (`playback_text`) from playback's data
// based on a user-configurable format string (app_config.playback_format)
Expand All @@ -144,6 +153,12 @@ fn render_playback_text(
// this regex is to handle a format argument or a newline
let re = regex::Regex::new(r"\{.*?\}|\n").unwrap();

// build the volume string (vol% when unmuted, old_vol% (muted) if currently muted)
let mut volume = format!("{}%", playback.volume.unwrap_or_default());
if mute_state.is_some() {
volume = format!("{}% (muted)", mute_state.unwrap_or_default());
}

let mut ptr = 0;
for m in re.find_iter(format_str) {
let s = m.start();
Expand Down Expand Up @@ -180,10 +195,10 @@ fn render_playback_text(
"{album}" => (track.album.name.to_owned(), ui.theme.playback_album()),
"{metadata}" => (
format!(
"repeat: {} | shuffle: {} | volume: {}% | device: {}",
"repeat: {} | shuffle: {} | volume: {} | device: {}",
<&'static str>::from(playback.repeat_state),
playback.shuffle_state,
playback.volume.unwrap_or_default(),
volume,
playback.device_name,
),
ui.theme.playback_metadata(),
Expand Down

0 comments on commit 8b7d9a0

Please sign in to comment.