Skip to content

Commit

Permalink
feat(command)!: replace Volume -Up / -Down with VolumeChange
Browse files Browse the repository at this point in the history
This change implements what was requested in aome510#616.
  • Loading branch information
DOD-101 committed Dec 8, 2024
1 parent 5087bde commit c62b0e5
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 72 deletions.
142 changes: 82 additions & 60 deletions spotify_player/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub enum Command {
Repeat,
ToggleFakeTrackRepeatMode,
Shuffle,
VolumeUp,
VolumeDown,
VolumeChange {
offset: i32,
},
Mute,
SeekForward,
SeekBackward,
Expand Down Expand Up @@ -284,77 +285,98 @@ pub fn construct_episode_actions(episode: &Episode, _data: &DataReadGuard) -> Ve
}

impl Command {
pub fn desc(self) -> &'static str {
pub fn desc(self) -> String {
match self {
Self::None => "do nothing",
Self::NextTrack => "next track",
Self::PreviousTrack => "previous track",
Self::ResumePause => "resume/pause based on the current playback",
Self::PlayRandom => "play a random track in the current context",
Self::Repeat => "cycle the repeat mode",
Self::ToggleFakeTrackRepeatMode => "toggle fake track repeat mode",
Self::Shuffle => "toggle the shuffle mode",
Self::VolumeUp => "increase playback volume by 5%",
Self::VolumeDown => "decrease playback volume by 5%",
Self::Mute => "toggle playback volume between 0% and previous level",
Self::SeekForward => "seek forward by 5s",
Self::SeekBackward => "seek backward by 5s",
Self::Quit => "quit the application",
Self::ClosePopup => "close a popup",
Self::None => "do nothing".to_string(),
Self::NextTrack => "next track".to_string(),
Self::PreviousTrack => "previous track".to_string(),
Self::ResumePause => "resume/pause based on the current playback".to_string(),
Self::PlayRandom => "play a random track in the current context".to_string(),
Self::Repeat => "cycle the repeat mode".to_string(),
Self::ToggleFakeTrackRepeatMode => "toggle fake track repeat mode".to_string(),
Self::Shuffle => "toggle the shuffle mode".to_string(),
Self::VolumeChange { offset } => format!("change the value by {}", offset),
Self::Mute => "toggle playback volume between 0% and previous level".to_string(),
Self::SeekForward => "seek forward by 5s".to_string(),
Self::SeekBackward => "seek backward by 5s".to_string(),
Self::Quit => "quit the application".to_string(),
Self::ClosePopup => "close a popup".to_string(),
#[cfg(feature = "streaming")]
Self::RestartIntegratedClient => "restart the integrated client",
Self::SelectNextOrScrollDown => "select the next item in a list/table or scroll down",
Self::RestartIntegratedClient => "restart the integrated client".to_string(),
Self::SelectNextOrScrollDown => {
"select the next item in a list/table or scroll down".to_string()
}
Self::SelectPreviousOrScrollUp => {
"select the previous item in a list/table or scroll up"
"select the previous item in a list/table or scroll up".to_string()
}
Self::PageSelectNextOrScrollDown => {
"select the next page item in a list/table or scroll a page down"
"select the next page item in a list/table or scroll a page down".to_string()
}
Self::PageSelectPreviousOrScrollUp => {
"select the previous page item in a list/table or scroll a page up"
"select the previous page item in a list/table or scroll a page up".to_string()
}
Self::SelectFirstOrScrollToTop => {
"select the first item in a list/table or scroll to the top"
"select the first item in a list/table or scroll to the top".to_string()
}
Self::SelectLastOrScrollToBottom => {
"select the last item in a list/table or scroll to the bottom"
"select the last item in a list/table or scroll to the bottom".to_string()
}
Self::ChooseSelected => "choose the selected item and act on it".to_string(),
Self::JumpToCurrentTrackInContext => {
"jump to the current track in the context".to_string()
}
Self::RefreshPlayback => "manually refresh the current playback".to_string(),
Self::ShowActionsOnSelectedItem => {
"open a popup showing actions on a selected item".to_string()
}
Self::ShowActionsOnCurrentTrack => {
"open a popup showing actions on the current track".to_string()
}
Self::AddSelectedItemToQueue => "add the selected item to queue".to_string(),
Self::FocusNextWindow => "focus the next focusable window (if any)".to_string(),
Self::FocusPreviousWindow => "focus the previous focusable window (if any)".to_string(),
Self::SwitchTheme => "open a popup for switching theme".to_string(),
Self::SwitchDevice => "open a popup for switching device".to_string(),
Self::Search => "open a popup for searching in the current page".to_string(),
Self::BrowseUserPlaylists => "open a popup for browsing user's playlists".to_string(),
Self::BrowseUserFollowedArtists => {
"open a popup for browsing user's followed artists".to_string()
}
Self::BrowseUserSavedAlbums => {
"open a popup for browsing user's saved albums".to_string()
}
Self::ChooseSelected => "choose the selected item and act on it",
Self::JumpToCurrentTrackInContext => "jump to the current track in the context",
Self::RefreshPlayback => "manually refresh the current playback",
Self::ShowActionsOnSelectedItem => "open a popup showing actions on a selected item",
Self::ShowActionsOnCurrentTrack => "open a popup showing actions on the current track",
Self::AddSelectedItemToQueue => "add the selected item to queue",
Self::FocusNextWindow => "focus the next focusable window (if any)",
Self::FocusPreviousWindow => "focus the previous focusable window (if any)",
Self::SwitchTheme => "open a popup for switching theme",
Self::SwitchDevice => "open a popup for switching device",
Self::Search => "open a popup for searching in the current page",
Self::BrowseUserPlaylists => "open a popup for browsing user's playlists",
Self::BrowseUserFollowedArtists => "open a popup for browsing user's followed artists",
Self::BrowseUserSavedAlbums => "open a popup for browsing user's saved albums",
Self::CurrentlyPlayingContextPage => "go to the currently playing context page",
Self::TopTrackPage => "go to the user top track page",
Self::RecentlyPlayedTrackPage => "go to the user recently played track page",
Self::LikedTrackPage => "go to the user liked track page",
Self::CurrentlyPlayingContextPage => {
"go to the currently playing context page".to_string()
}
Self::TopTrackPage => "go to the user top track page".to_string(),
Self::RecentlyPlayedTrackPage => {
"go to the user recently played track page".to_string()
}
Self::LikedTrackPage => "go to the user liked track page".to_string(),
#[cfg(feature = "lyric-finder")]
Self::LyricPage => "go to the lyric page of the current track",
Self::LibraryPage => "go to the user library page",
Self::SearchPage => "go to the search page",
Self::BrowsePage => "go to the browse page",
Self::Queue => "go to the queue page",
Self::OpenCommandHelp => "go to the command help page",
Self::PreviousPage => "go to the previous page",
Self::OpenSpotifyLinkFromClipboard => "open a Spotify link from clipboard",
Self::SortTrackByTitle => "sort the track table (if any) by track's title",
Self::SortTrackByArtists => "sort the track table (if any) by track's artists",
Self::SortTrackByAlbum => "sort the track table (if any) by track's album",
Self::SortTrackByDuration => "sort the track table (if any) by track's duration",
Self::SortTrackByAddedDate => "sort the track table (if any) by track's added date",
Self::ReverseTrackOrder => "reverse the order of the track table (if any)",
Self::MovePlaylistItemUp => "move playlist item up one position",
Self::MovePlaylistItemDown => "move playlist item down one position",
Self::CreatePlaylist => "create a new playlist",
Self::LyricPage => "go to the lyric page of the current track".to_string(),
Self::LibraryPage => "go to the user library page".to_string(),
Self::SearchPage => "go to the search page".to_string(),
Self::BrowsePage => "go to the browse page".to_string(),
Self::Queue => "go to the queue page".to_string(),
Self::OpenCommandHelp => "go to the command help page".to_string(),
Self::PreviousPage => "go to the previous page".to_string(),
Self::OpenSpotifyLinkFromClipboard => "open a Spotify link from clipboard".to_string(),
Self::SortTrackByTitle => "sort the track table (if any) by track's title".to_string(),
Self::SortTrackByArtists => {
"sort the track table (if any) by track's artists".to_string()
}
Self::SortTrackByAlbum => "sort the track table (if any) by track's album".to_string(),
Self::SortTrackByDuration => {
"sort the track table (if any) by track's duration".to_string()
}
Self::SortTrackByAddedDate => {
"sort the track table (if any) by track's added date".to_string()
}
Self::ReverseTrackOrder => "reverse the order of the track table (if any)".to_string(),
Self::MovePlaylistItemUp => "move playlist item up one position".to_string(),
Self::MovePlaylistItemDown => "move playlist item down one position".to_string(),
Self::CreatePlaylist => "create a new playlist".to_string(),
}
}
}
4 changes: 2 additions & 2 deletions spotify_player/src/config/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ impl Default for KeymapConfig {
},
Keymap {
key_sequence: "+".into(),
command: Command::VolumeUp,
command: Command::VolumeChange { offset: 5 },
},
Keymap {
key_sequence: "-".into(),
command: Command::VolumeDown,
command: Command::VolumeChange { offset: -5 },
},
Keymap {
key_sequence: "_".into(),
Expand Down
12 changes: 2 additions & 10 deletions spotify_player/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,18 +547,10 @@ fn handle_global_command(
Command::Shuffle => {
client_pub.send(ClientRequest::Player(PlayerRequest::Shuffle))?;
}
Command::VolumeUp => {
Command::VolumeChange { offset } => {
if let Some(ref playback) = state.player.read().buffered_playback {
if let Some(volume) = playback.volume {
let volume = std::cmp::min(volume + 5, 100_u32);
client_pub.send(ClientRequest::Player(PlayerRequest::Volume(volume as u8)))?;
}
}
}
Command::VolumeDown => {
if let Some(ref playback) = state.player.read().buffered_playback {
if let Some(volume) = playback.volume {
let volume = volume.saturating_sub(5_u32);
let volume = std::cmp::min(volume as i32 + offset, 100_i32);
client_pub.send(ClientRequest::Player(PlayerRequest::Volume(volume as u8)))?;
}
}
Expand Down

0 comments on commit c62b0e5

Please sign in to comment.