fix(context): fix playback context tracking bugs
Multiple critical fixes for context tracking: 1. Add 'local_library' to backend context type parser - Was rejecting 'local_library' causing "Invalid context type" error - Now properly recognized in set_playback_context command 2. Fix shuffle to not always start with first track - Removed logic that moved current track to front of shuffle - Now finds current track position in shuffled order instead - Shuffle is truly random, not biased to original order 3. Add missing await to all setPlaybackContext calls - PlaylistDetailView: await context creation - FavoritesView: make setFavoritesContext async + await calls - ArtistDetailView: await context creation - HomeView: await context creation - SearchView: await + use home_list type (search type doesn't exist) This fixes intermittent context tracking (race condition) Fixes: shuffle starting with first song, Local Library context error, intermittent playlist/favorites/artist/home/search context tracking cc
This commit is contained in:
1 parent
f2c3e8aedd
commit
ed7984a029
7 files changed
+24
-20
No files matched your search
@@ -28,6 +28,7 @@ pub fn set_playback_context(
|
||||
"artist_top" => ContextType::ArtistTop,
|
||||
"home_list" => ContextType::HomeList,
|
||||
"favorites" => ContextType::Favorites,
|
||||
"local_library" => ContextType::LocalLibrary,
|
||||
_ => return Err(format!("Invalid context type: {}", context_type)),
|
||||
};
|
||||
|
||||
|
||||
@@ -525,15 +525,18 @@ impl QueueManager {
|
||||
order.swap(i, j);
|
||||
}
|
||||
|
||||
// If there's a current track, move it to the front
|
||||
if let Some(curr_idx) = state.current_index {
|
||||
if let Some(pos) = order.iter().position(|&x| x == curr_idx) {
|
||||
order.remove(pos);
|
||||
order.insert(0, curr_idx);
|
||||
}
|
||||
}
|
||||
|
||||
state.shuffle_order = order;
|
||||
state.shuffle_position = 0;
|
||||
|
||||
// If there's a current track, find its position in the new shuffle order
|
||||
// (don't move it to front, just update our position in the shuffled list)
|
||||
if let Some(curr_idx) = state.current_index {
|
||||
if let Some(pos) = state.shuffle_order.iter().position(|&x| x == curr_idx) {
|
||||
state.shuffle_position = pos;
|
||||
} else {
|
||||
state.shuffle_position = 0;
|
||||
}
|
||||
} else {
|
||||
state.shuffle_position = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,7 +330,7 @@
|
||||
const index = trackIndex !== undefined ? trackIndex : trackIds.indexOf(track.id);
|
||||
|
||||
if (index >= 0) {
|
||||
setPlaybackContext(
|
||||
await setPlaybackContext(
|
||||
'artist_top',
|
||||
artist.id.toString(),
|
||||
artist.name,
|
||||
|
||||
@@ -741,9 +741,9 @@
|
||||
}));
|
||||
}
|
||||
|
||||
function setFavoritesContext(trackIds: number[], index: number) {
|
||||
async function setFavoritesContext(trackIds: number[], index: number) {
|
||||
if (trackIds.length === 0) return;
|
||||
setPlaybackContext(
|
||||
await setPlaybackContext(
|
||||
'favorites',
|
||||
'favorites',
|
||||
'Favorites',
|
||||
@@ -761,7 +761,7 @@
|
||||
|
||||
async function handleTrackClick(track: FavoriteTrack, index: number) {
|
||||
const trackIds = filteredTracks.map(t => t.id);
|
||||
setFavoritesContext(trackIds, index);
|
||||
await setFavoritesContext(trackIds, index);
|
||||
|
||||
try {
|
||||
await setFavoritesQueue(index);
|
||||
@@ -779,7 +779,7 @@
|
||||
|
||||
try {
|
||||
await setFavoritesQueue(0);
|
||||
setFavoritesContext(filteredTracks.map(t => t.id), 0);
|
||||
await setFavoritesContext(filteredTracks.map(t => t.id), 0);
|
||||
onTrackPlay(buildDisplayTrack(filteredTracks[0], 0));
|
||||
} catch (err) {
|
||||
console.error('Failed to set queue:', err);
|
||||
|
||||
@@ -357,8 +357,8 @@
|
||||
// Create continue listening context
|
||||
if (continueTracks.length > 0) {
|
||||
const trackIds = continueTracks.map(t => t.id);
|
||||
|
||||
setPlaybackContext(
|
||||
|
||||
await setPlaybackContext(
|
||||
'home_list',
|
||||
'continue_listening',
|
||||
'Continue Listening',
|
||||
|
||||
@@ -585,7 +585,7 @@
|
||||
const contextIndex = trackIds.indexOf(track.id);
|
||||
|
||||
if (contextIndex >= 0 && trackIds.length > 0) {
|
||||
setPlaybackContext(
|
||||
await setPlaybackContext(
|
||||
'playlist',
|
||||
playlist.id.toString(),
|
||||
playlist.name,
|
||||
|
||||
@@ -399,9 +399,9 @@
|
||||
// Create search results context
|
||||
if (trackResults && trackResults.items.length > 0) {
|
||||
const trackIds = trackResults.items.map(t => t.id);
|
||||
|
||||
setPlaybackContext(
|
||||
'search',
|
||||
|
||||
await setPlaybackContext(
|
||||
'home_list', // Using home_list for search results (search type doesn't exist yet)
|
||||
currentQuery,
|
||||
`Search: ${currentQuery}`,
|
||||
'qobuz',
|
||||
|
||||
Reference in new issue
Block a user