Skip to content
Merged
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
9 changes: 8 additions & 1 deletion spotify_player/src/client/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ fn handle_page_change_event(
} => {
let expected_id = match context_page_type {
ContextPageType::Browsing(context_id) => Some(context_id.clone()),
ContextPageType::CurrentPlaying => state.player.read().playing_context_id(),
ContextPageType::CurrentPlaying { tracks_id } => {
// If we have a stored tracks_id, use it; otherwise get from player
if let Some(tracks_id) = tracks_id {
Some(ContextId::Tracks(tracks_id.clone()))
} else {
state.player.read().playing_context_id()
}
}
};

let new_id = if *id == expected_id {
Expand Down
9 changes: 8 additions & 1 deletion spotify_player/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,12 @@ fn handle_global_command(
}
}
Command::CurrentlyPlayingContextPage => {
// Use the currently playing Tracks context if available
let tracks_id = ui.currently_playing_tracks_id.clone();

ui.new_page(PageState::Context {
id: None,
context_page_type: ContextPageType::CurrentPlaying,
context_page_type: ContextPageType::CurrentPlaying { tracks_id },
state: None,
});
}
Expand Down Expand Up @@ -732,6 +735,10 @@ fn handle_global_command(
// for track link, play the song
"track" => {
let id = TrackId::from_id(id)?.into_static();

// Clear Tracks context when playing from clipboard link
ui.currently_playing_tracks_id = None;

client_pub.send(ClientRequest::Player(PlayerRequest::StartPlayback(
Playback::URIs(vec![id.into()], None),
None,
Expand Down
21 changes: 21 additions & 0 deletions spotify_player/src/event/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ fn handle_command_for_track_table_window(
filtered_tracks[id].id.uri()
};

// Update currently_playing_tracks_id based on the context
match context_id {
Some(ContextId::Tracks(ref tracks_id)) => {
ui.currently_playing_tracks_id = Some(tracks_id.clone());
}
_ => {
ui.currently_playing_tracks_id = None;
}
}

let base_playback = match context_id {
None | Some(ContextId::Tracks(_)) => {
Playback::URIs(tracks.iter().map(|t| t.id.clone().into()).collect(), None)
Expand Down Expand Up @@ -381,6 +391,10 @@ pub fn handle_command_for_track_list_window(
// This is different from the track table, which handles
// `ChooseSelected` by starting a `URIs` playback
// containing all the tracks in the table.

// Track lists are used for search results, so clear the Tracks context
ui.currently_playing_tracks_id = None;

client_pub.send(ClientRequest::Player(PlayerRequest::StartPlayback(
Playback::URIs(vec![tracks[id].id.clone().into()], None),
None,
Expand Down Expand Up @@ -587,6 +601,9 @@ pub fn handle_command_for_episode_list_window(
}
match command {
Command::ChooseSelected => {
// Episodes don't have a Tracks context, so clear it
ui.currently_playing_tracks_id = None;

client_pub.send(ClientRequest::Player(PlayerRequest::StartPlayback(
Playback::URIs(vec![episodes[id].id.clone().into()], None),
None,
Expand Down Expand Up @@ -629,6 +646,10 @@ fn handle_command_for_episode_table_window(
match command {
Command::ChooseSelected => {
let uri = episodes[id].id.uri();

// Show context doesn't have a Tracks context, so clear it
ui.currently_playing_tracks_id = None;

client_pub.send(ClientRequest::Player(PlayerRequest::StartPlayback(
Playback::Context(
ContextId::Show(show_id.clone_static()),
Expand Down
5 changes: 5 additions & 0 deletions spotify_player/src/state/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub struct UIState {
/// Count prefix for vim-style navigation (e.g., 5j, 10k)
pub count_prefix: Option<usize>,

/// The currently playing Tracks context
pub currently_playing_tracks_id: Option<TracksId>,

#[cfg(feature = "image")]
pub last_cover_image_render_info: ImageRenderInfo,
}
Expand Down Expand Up @@ -122,6 +125,8 @@ impl Default for UIState {

count_prefix: None,

currently_playing_tracks_id: None,

#[cfg(feature = "image")]
last_cover_image_render_info: ImageRenderInfo::default(),
}
Expand Down
6 changes: 3 additions & 3 deletions spotify_player/src/state/ui/page.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
state::model::{Category, ContextId},
state::model::{Category, ContextId, TracksId},
ui::single_line_input::LineInput,
};
use ratatui::widgets::{ListState, TableState};
Expand Down Expand Up @@ -68,7 +68,7 @@ pub struct SearchPageUIState {

#[derive(Clone, Debug)]
pub enum ContextPageType {
CurrentPlaying,
CurrentPlaying { tracks_id: Option<TracksId> },
Browsing(ContextId),
}

Expand Down Expand Up @@ -268,7 +268,7 @@ impl SearchPageUIState {
impl ContextPageType {
pub fn title(&self) -> String {
match self {
ContextPageType::CurrentPlaying => String::from("Current Playing"),
ContextPageType::CurrentPlaying { .. } => String::from("Current Playing"),
ContextPageType::Browsing(id) => match id {
ContextId::Playlist(_) => String::from("Playlist"),
ContextId::Album(_) => String::from("Album"),
Expand Down