Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ NOTES*
# Generated html files for live previewing markdown
*.html

.idea
.idea
.vscode
2 changes: 2 additions & 0 deletions spotify_player/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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,

Expand Down
4 changes: 3 additions & 1 deletion spotify_player/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down
1 change: 1 addition & 0 deletions spotify_player/src/event/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ pub fn handle_key_sequence_for_popup(
},
)
}
PopupState::AddedToQueue { frames_left: _ } => Ok(false)
}
}

Expand Down
1 change: 1 addition & 0 deletions spotify_player/src/event/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 11 additions & 3 deletions spotify_player/src/state/ui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum PopupState {
desc: LineInput,
current_field: PlaylistCreateCurrentField,
},
AddedToQueue { frames_left: u16 },
ConfirmAction {
message: String,
action: ConfirmableAction,
Expand Down Expand Up @@ -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,

}
}

Expand All @@ -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,
}
}

Expand Down
15 changes: 15 additions & 0 deletions spotify_player/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -90,6 +92,19 @@ fn init_ui() -> Result<Terminal> {
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()?;
Expand Down
20 changes: 19 additions & 1 deletion spotify_player/src/ui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down