diff --git a/.gitignore b/.gitignore index e37f77fe..3fd91a52 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ NOTES* # Generated html files for live previewing markdown *.html -.idea \ No newline at end of file +.idea +.vscode \ No newline at end of file diff --git a/spotify_player/src/config/mod.rs b/spotify_player/src/config/mod.rs index 1987d900..2ac0c682 100644 --- a/spotify_player/src/config/mod.rs +++ b/spotify_player/src/config/mod.rs @@ -81,6 +81,7 @@ pub struct AppConfig { // duration configs pub app_refresh_duration_in_ms: u64, pub playback_refresh_duration_in_ms: u64, + pub added_to_queue_popup_duration_in_frames: u16, pub page_size_in_rows: usize, @@ -331,6 +332,7 @@ impl Default for AppConfig { ap_port: None, app_refresh_duration_in_ms: 32, playback_refresh_duration_in_ms: 0, + added_to_queue_popup_duration_in_frames: 45, page_size_in_rows: 20, diff --git a/spotify_player/src/event/mod.rs b/spotify_player/src/event/mod.rs index 660453d3..70a3c472 100644 --- a/spotify_player/src/event/mod.rs +++ b/spotify_player/src/event/mod.rs @@ -139,7 +139,9 @@ fn handle_key_event( ui.count_prefix ); let handled = { - if ui.popup.is_none() { + if ui.popup.is_none() + || matches!(ui.popup, Some(PopupState::AddedToQueue { frames_left: _ })) + { page::handle_key_sequence_for_page(&key_sequence, client_pub, state, &mut ui)? } else { popup::handle_key_sequence_for_popup(&key_sequence, client_pub, state, &mut ui)? diff --git a/spotify_player/src/event/popup.rs b/spotify_player/src/event/popup.rs index 55540785..b2ff09e0 100644 --- a/spotify_player/src/event/popup.rs +++ b/spotify_player/src/event/popup.rs @@ -312,6 +312,7 @@ pub fn handle_key_sequence_for_popup( }, ) } + PopupState::AddedToQueue { frames_left: _ } => Ok(false) } } diff --git a/spotify_player/src/event/window.rs b/spotify_player/src/event/window.rs index e47d1c3d..c084a710 100644 --- a/spotify_player/src/event/window.rs +++ b/spotify_player/src/event/window.rs @@ -349,6 +349,7 @@ fn handle_command_for_track_table_window( client_pub.send(ClientRequest::AddPlayableToQueue( filtered_tracks[id].id.clone().into(), ))?; + ui.popup = Some(PopupState::AddedToQueue { frames_left: config::get_config().app_config.added_to_queue_popup_duration_in_frames }); } Command::JumpToHighlightTrackInContext => { ui.popup = None; diff --git a/spotify_player/src/state/ui/popup.rs b/spotify_player/src/state/ui/popup.rs index 806e8421..1fa42beb 100644 --- a/spotify_player/src/state/ui/popup.rs +++ b/spotify_player/src/state/ui/popup.rs @@ -32,6 +32,7 @@ pub enum PopupState { desc: LineInput, current_field: PlaylistCreateCurrentField, }, + AddedToQueue { frames_left: u16 }, ConfirmAction { message: String, action: ConfirmableAction, @@ -94,7 +95,11 @@ impl PopupState { | Self::ArtistList(.., list_state) | Self::ThemeList(.., list_state) | Self::ActionList(.., list_state) => Some(list_state), - Self::Search { .. } | Self::PlaylistCreate { .. } | Self::ConfirmAction { .. } => None, + Self::Search { .. } + | Self::PlaylistCreate { .. } + | Self::AddedToQueue { frames_left: _ } + | Self::ConfirmAction { .. } => None, + } } @@ -107,8 +112,11 @@ impl PopupState { | Self::UserSavedAlbumList(list_state) | Self::ArtistList(.., list_state) | Self::ThemeList(.., list_state) - | Self::ActionList(.., list_state) => Some(list_state), - Self::Search { .. } | Self::PlaylistCreate { .. } | Self::ConfirmAction { .. } => None, + | Self::ActionList(.., list_state) => Some(list_state), + Self::Search { .. } + | Self::PlaylistCreate { .. } + | Self::AddedToQueue { frames_left: _ } + | Self::ConfirmAction { .. } => None, } } diff --git a/spotify_player/src/ui/mod.rs b/spotify_player/src/ui/mod.rs index 89aad3b2..443996d8 100644 --- a/spotify_player/src/ui/mod.rs +++ b/spotify_player/src/ui/mod.rs @@ -49,6 +49,8 @@ pub fn run(state: &SharedState) -> Result<()> { std::process::exit(0); } + update_ui_state(&mut ui); + let terminal_size = terminal.size()?; if Some(terminal_size) != last_terminal_size { last_terminal_size = Some(terminal_size); @@ -90,6 +92,19 @@ fn init_ui() -> Result { Ok(terminal) } +// Perform per-frame updates to the UI state +fn update_ui_state(ui: &mut UIStateGuard) { + match &mut ui.popup { + Some(PopupState::AddedToQueue { frames_left }) => { + *frames_left -= 1; + if *frames_left <= 0 { + ui.popup = None; + } + } + _ => {} + } +} + /// Clean up UI resources before quitting the application fn clean_up(mut terminal: Terminal) -> Result<()> { crossterm::terminal::disable_raw_mode()?; diff --git a/spotify_player/src/ui/popup.rs b/spotify_player/src/ui/popup.rs index 46241079..c43fb73e 100644 --- a/spotify_player/src/ui/popup.rs +++ b/spotify_player/src/ui/popup.rs @@ -196,6 +196,25 @@ pub fn render_popup( let rect = render_list_popup(frame, rect, "Artists", items, 5, ui); (rect, false) } + PopupState::AddedToQueue { .. } => { + let chunks = + Layout::vertical([Constraint::Fill(0), Constraint::Length(3)]).split(rect); + + let popup_rect = construct_and_render_block( + "Queued", + &ui.theme, + Borders::ALL, + frame, + chunks[1], + ); + + frame.render_widget( + Paragraph::new("✔ Item added to queue!"), + popup_rect, + ); + + (chunks[0], true) + } PopupState::ConfirmAction { message, .. } => { let chunks = Layout::vertical([Constraint::Fill(0), Constraint::Length(3)]).split(rect); @@ -207,7 +226,6 @@ pub fn render_popup( frame, chunks[1], ); - frame.render_widget(Paragraph::new(format!("{message} (y/n)")), confirm_rect); (chunks[0], true)