From c10e57afbb2a9da0fb77724fdf0c28869e8cff35 Mon Sep 17 00:00:00 2001 From: Chris Jansen Date: Thu, 25 Dec 2025 22:07:50 +0100 Subject: [PATCH 1/3] lil popup when you queue, doesn't disappear yet though --- .vscode/launch.json | 19 +++++++++++++++++++ .vscode/tasks.json | 14 ++++++++++++++ spotify_player/src/event/mod.rs | 4 +++- spotify_player/src/event/popup.rs | 1 + spotify_player/src/event/window.rs | 1 + spotify_player/src/state/ui/popup.rs | 11 +++++++++-- spotify_player/src/ui/popup.rs | 26 +++++++++++++++++++++++++- 7 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..33bfaa97 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Debug Rust", + "type": "lldb", + "request": "launch", + "cargo": { + "args": ["build"] + }, + "program": "${workspaceFolder}/target/debug/spotify_player", + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..88381fe7 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,14 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cargo", + "command": "build", + "problemMatcher": [ + "$rustc" + ], + "group": "build", + "label": "rust: cargo build" + } + ] +} \ No newline at end of file diff --git a/spotify_player/src/event/mod.rs b/spotify_player/src/event/mod.rs index ea79a22a..e99d2c15 100644 --- a/spotify_player/src/event/mod.rs +++ b/spotify_player/src/event/mod.rs @@ -115,7 +115,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 117a3c94..e0f73056 100644 --- a/spotify_player/src/event/popup.rs +++ b/spotify_player/src/event/popup.rs @@ -299,6 +299,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 e9c5ad03..5fd23409 100644 --- a/spotify_player/src/event/window.rs +++ b/spotify_player/src/event/window.rs @@ -336,6 +336,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: 120 }); } Command::JumpToHighlightTrackInContext => { ui.popup = None; diff --git a/spotify_player/src/state/ui/popup.rs b/spotify_player/src/state/ui/popup.rs index a69415ab..58b5f5ec 100644 --- a/spotify_player/src/state/ui/popup.rs +++ b/spotify_player/src/state/ui/popup.rs @@ -28,6 +28,7 @@ pub enum PopupState { desc: LineInput, current_field: PlaylistCreateCurrentField, }, + AddedToQueue { frames_left: u16 } } #[derive(Debug, Clone)] @@ -77,7 +78,10 @@ impl PopupState { | Self::ArtistList(.., list_state) | Self::ThemeList(.., list_state) | Self::ActionList(.., list_state) => Some(list_state), - Self::Search { .. } | Self::PlaylistCreate { .. } => None, + + Self::Search { .. } + | Self::PlaylistCreate { .. } + | Self::AddedToQueue { frames_left: _ } => None, } } @@ -91,7 +95,10 @@ impl PopupState { | Self::ArtistList(.., list_state) | Self::ThemeList(.., list_state) | Self::ActionList(.., list_state) => Some(list_state), - Self::Search { .. } | Self::PlaylistCreate { .. } => None, + + Self::Search { .. } + | Self::PlaylistCreate { .. } + | Self::AddedToQueue { frames_left: _ } => None, } } diff --git a/spotify_player/src/ui/popup.rs b/spotify_player/src/ui/popup.rs index a133ef65..7b8164cb 100644 --- a/spotify_player/src/ui/popup.rs +++ b/spotify_player/src/ui/popup.rs @@ -21,7 +21,7 @@ pub fn render_popup( ui: &mut UIStateGuard, rect: Rect, ) -> (Rect, bool) { - match ui.popup { + match ui.popup.as_mut() { None => (rect, true), Some(ref popup) => match popup { PopupState::PlaylistCreate { @@ -196,6 +196,30 @@ pub fn render_popup( let rect = render_list_popup(frame, rect, "Artists", items, 5, ui); (rect, false) } + PopupState::AddedToQueue {frames_left } => { + 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, + ); + + *frames_left -= 1; + if *frames_left <= 0 { + ui.popup = None; + } + + (chunks[0], true) + } }, } } From 5dc1b482156c3a3dad25c29e786c427ac78bba88 Mon Sep 17 00:00:00 2001 From: Chris Jansen Date: Sat, 24 Jan 2026 14:37:03 +0100 Subject: [PATCH 2/3] remove .vscode and add it to gitignore --- .gitignore | 3 ++- .vscode/launch.json | 19 ------------------- .vscode/tasks.json | 14 -------------- 3 files changed, 2 insertions(+), 34 deletions(-) delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 508091aa..c8584289 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,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/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 33bfaa97..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Debug Rust", - "type": "lldb", - "request": "launch", - "cargo": { - "args": ["build"] - }, - "program": "${workspaceFolder}/target/debug/spotify_player", - "args": [], - "cwd": "${workspaceFolder}" - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 88381fe7..00000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "cargo", - "command": "build", - "problemMatcher": [ - "$rustc" - ], - "group": "build", - "label": "rust: cargo build" - } - ] -} \ No newline at end of file From 55bba68937b6d299b1074bfdff15b205a393ad0e Mon Sep 17 00:00:00 2001 From: Chris Jansen Date: Sat, 24 Jan 2026 15:03:04 +0100 Subject: [PATCH 3/3] move frames_left update logic to UI Module, introduce config with default for frames_left and got the disappearing of the popup working --- spotify_player/src/config/mod.rs | 2 ++ spotify_player/src/event/window.rs | 2 +- spotify_player/src/ui/mod.rs | 15 +++++++++++++++ spotify_player/src/ui/popup.rs | 9 ++------- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/spotify_player/src/config/mod.rs b/spotify_player/src/config/mod.rs index 84a975f3..103503a8 100644 --- a/spotify_player/src/config/mod.rs +++ b/spotify_player/src/config/mod.rs @@ -77,6 +77,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, @@ -305,6 +306,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/window.rs b/spotify_player/src/event/window.rs index 5fd23409..03515705 100644 --- a/spotify_player/src/event/window.rs +++ b/spotify_player/src/event/window.rs @@ -336,7 +336,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: 120 }); + 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/ui/mod.rs b/spotify_player/src/ui/mod.rs index ba1b2c49..dc21d26a 100644 --- a/spotify_player/src/ui/mod.rs +++ b/spotify_player/src/ui/mod.rs @@ -47,6 +47,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); @@ -88,6 +90,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 7b8164cb..fbc7a02d 100644 --- a/spotify_player/src/ui/popup.rs +++ b/spotify_player/src/ui/popup.rs @@ -21,7 +21,7 @@ pub fn render_popup( ui: &mut UIStateGuard, rect: Rect, ) -> (Rect, bool) { - match ui.popup.as_mut() { + match ui.popup { None => (rect, true), Some(ref popup) => match popup { PopupState::PlaylistCreate { @@ -196,7 +196,7 @@ pub fn render_popup( let rect = render_list_popup(frame, rect, "Artists", items, 5, ui); (rect, false) } - PopupState::AddedToQueue {frames_left } => { + PopupState::AddedToQueue { .. } => { let chunks = Layout::vertical([Constraint::Fill(0), Constraint::Length(3)]).split(rect); @@ -213,11 +213,6 @@ pub fn render_popup( popup_rect, ); - *frames_left -= 1; - if *frames_left <= 0 { - ui.popup = None; - } - (chunks[0], true) } },