Migrate all queue operations to V2 commands

- Add V2 queue commands: v2_set_shuffle, v2_move_queue_track,
  v2_add_tracks_to_queue, v2_add_tracks_to_queue_next,
  v2_remove_upcoming_track
- Migrate queueStore.ts to use all V2 queue commands
- Update all view components to use V2 queue commands:
  - HomeView, SearchView, ArtistDetailView, FavoritesView
  - LocalLibraryView, PlaylistDetailView
- Update +page.svelte to use V2 shuffle, repeat, and remove commands

No legacy queue commands are called from frontend anymore.
This commit is contained in:
vicrodh committed 2026-02-14 23:21:19 -06:00
1 parent 67ed397d02
commit 6cea4149c0
10 files changed
+123 -56

No files matched your search

+61
View File
@@ -401,6 +401,17 @@ pub async fn v2_toggle_shuffle(
Ok(bridge.toggle_shuffle().await)
}
/// Set shuffle mode directly (V2)
#[tauri::command]
pub async fn v2_set_shuffle(
enabled: bool,
app_state: State<'_, AppState>,
) -> Result<(), String> {
log::info!("[V2] set_shuffle: {}", enabled);
app_state.queue.set_shuffle(enabled);
Ok(())
}
/// Clear the queue (V2 - uses QbzCore)
#[tauri::command]
pub async fn v2_clear_queue(
@@ -530,6 +541,17 @@ pub async fn v2_remove_from_queue(
Ok(())
}
/// Remove a track from the upcoming queue by its position (V2)
/// (0 = first upcoming track, handles shuffle mode correctly)
#[tauri::command]
pub async fn v2_remove_upcoming_track(
upcoming_index: usize,
app_state: State<'_, AppState>,
) -> Result<Option<V2QueueTrack>, String> {
log::info!("[V2] remove_upcoming_track: upcoming_index {}", upcoming_index);
Ok(app_state.queue.remove_upcoming_track(upcoming_index).map(Into::into))
}
/// Skip to next track in queue (V2)
#[tauri::command]
pub async fn v2_next_track(
@@ -561,6 +583,45 @@ pub async fn v2_play_queue_index(
Ok(track.map(Into::into))
}
/// Move a track within the queue (V2)
#[tauri::command]
pub async fn v2_move_queue_track(
from_index: usize,
to_index: usize,
app_state: State<'_, AppState>,
) -> Result<bool, String> {
log::info!("[V2] move_queue_track: {} -> {}", from_index, to_index);
Ok(app_state.queue.move_track(from_index, to_index))
}
/// Add multiple tracks to queue (V2)
#[tauri::command]
pub async fn v2_add_tracks_to_queue(
tracks: Vec<V2QueueTrack>,
app_state: State<'_, AppState>,
) -> Result<(), String> {
log::info!("[V2] add_tracks_to_queue: {} tracks", tracks.len());
let queue_tracks: Vec<crate::queue::QueueTrack> = tracks.into_iter().map(|t| t.into()).collect();
app_state.queue.add_tracks(queue_tracks);
Ok(())
}
/// Add multiple tracks to play next (V2)
/// Tracks are added in reverse order so they play in the order provided
#[tauri::command]
pub async fn v2_add_tracks_to_queue_next(
tracks: Vec<V2QueueTrack>,
app_state: State<'_, AppState>,
) -> Result<(), String> {
log::info!("[V2] add_tracks_to_queue_next: {} tracks", tracks.len());
// Add in reverse order so they end up in the correct order
for track in tracks.into_iter().rev() {
let queue_track: crate::queue::QueueTrack = track.into();
app_state.queue.add_track_next(queue_track);
}
Ok(())
}
// ==================== Search Commands (V2) ====================
/// Search for albums (V2 - uses QbzCore)
+5
View File
@@ -1107,14 +1107,19 @@ pub fn run() {
commands_v2::v2_get_queue_state,
commands_v2::v2_set_repeat_mode,
commands_v2::v2_toggle_shuffle,
commands_v2::v2_set_shuffle,
commands_v2::v2_clear_queue,
commands_v2::v2_add_to_queue,
commands_v2::v2_add_to_queue_next,
commands_v2::v2_set_queue,
commands_v2::v2_remove_from_queue,
commands_v2::v2_remove_upcoming_track,
commands_v2::v2_next_track,
commands_v2::v2_previous_track,
commands_v2::v2_play_queue_index,
commands_v2::v2_move_queue_track,
commands_v2::v2_add_tracks_to_queue,
commands_v2::v2_add_tracks_to_queue_next,
// Search
commands_v2::v2_search_albums,
commands_v2::v2_search_tracks,
@@ -851,7 +851,7 @@
console.log(`[Artist] Context created: "${artist.name}" top tracks, ${trackIds.length} tracks, starting at ${index}`);
try {
const queueTracks = buildTopTracksQueue(topTracks);
await invoke('set_queue', { tracks: queueTracks, startIndex: index });
await invoke('v2_set_queue', { tracks: queueTracks, startIndex: index });
} catch (err) {
console.error('Failed to set queue:', err);
}
@@ -1082,7 +1082,7 @@
async function setFavoritesQueue(startIndex: number) {
if (filteredTracks.length === 0) return;
const queueTracks = buildFavoritesQueueTracks(filteredTracks);
await invoke('set_queue', { tracks: queueTracks, startIndex });
await invoke('v2_set_queue', { tracks: queueTracks, startIndex });
}
async function handleTrackClick(track: FavoriteTrack, index: number) {
@@ -1119,7 +1119,7 @@
// Shuffle the tracks
const shuffled = [...filteredTracks].sort(() => Math.random() - 0.5);
const queueTracks = buildFavoritesQueueTracks(shuffled);
await invoke('set_queue', { tracks: queueTracks, startIndex: 0 });
await invoke('v2_set_queue', { tracks: queueTracks, startIndex: 0 });
await setFavoritesContext(shuffled.map(trk => trk.id), 0);
onTrackPlay(buildDisplayTrack(shuffled[0], 0));
} catch (err) {
@@ -1132,7 +1132,7 @@
try {
const queueTracks = buildFavoritesQueueTracks(filteredTracks);
await invoke('add_to_queue_next', { tracks: queueTracks });
await invoke('v2_add_tracks_to_queue_next', { tracks: queueTracks });
} catch (err) {
console.error('Failed to add tracks next:', err);
}
@@ -1143,7 +1143,7 @@
try {
const queueTracks = buildFavoritesQueueTracks(filteredTracks);
await invoke('add_to_queue', { tracks: queueTracks });
await invoke('v2_add_tracks_to_queue', { tracks: queueTracks });
} catch (err) {
console.error('Failed to add tracks to queue:', err);
}
+1 -1
View File
@@ -620,7 +620,7 @@
if (continueTracks.length > 0) {
try {
const queueTracks = buildContinueQueueTracks(continueTracks);
await invoke('set_queue', { tracks: queueTracks, startIndex: trackIndex });
await invoke('v2_set_queue', { tracks: queueTracks, startIndex: trackIndex });
} catch (err) {
console.error('Failed to set queue:', err);
}
@@ -1943,8 +1943,8 @@
try {
console.log('[LocalLibrary Shuffle] Starting shuffle with', albumTracks.length, 'tracks');
// Enable shuffle mode first
await invoke('set_shuffle', { enabled: true });
// Enable shuffle mode first (V2)
await invoke('v2_set_shuffle', { enabled: true });
// Pick a random track to start with
const randomIndex = Math.floor(Math.random() * albumTracks.length);
@@ -2124,7 +2124,7 @@
console.log('[LocalLibrary Queue] Mapped to', queueTracks.length, 'queue tracks');
console.log('[LocalLibrary Queue] Track IDs:', queueTracks.map(track => track.id));
await invoke('set_queue', { tracks: queueTracks, startIndex });
await invoke('v2_set_queue', { tracks: queueTracks, startIndex });
onSetLocalQueue?.(tracks.filter(track => track.source !== 'plex').map(track => track.id));
console.log('[LocalLibrary Queue] Queue set successfully');
@@ -1473,7 +1473,7 @@
const allTracks = displayTracks;
if (allTracks.length === 0) return;
const { queueTracks, localIds } = buildQueueTracks(allTracks);
await invoke('set_queue', { tracks: queueTracks, startIndex });
await invoke('v2_set_queue', { tracks: queueTracks, startIndex });
if (localIds.length > 0) {
onSetLocalQueue?.(localIds);
}
@@ -1801,7 +1801,7 @@
async function handleShuffle() {
if (tracks.length > 0 && onTrackPlay) {
try {
await invoke('set_shuffle', { enabled: true });
await invoke('v2_set_shuffle', { enabled: true });
await handlePlayAll();
} catch (err) {
console.error('Failed to shuffle:', err);
@@ -1827,12 +1827,8 @@
.filter(trk => trk.isLocal)
.map(trk => Math.abs(trk.id));
// Add in reverse order so first track ends up right after current
for (let i = playableTracks.length - 1; i >= 0; i--) {
const trk = playableTracks[i];
try {
await invoke('add_to_queue_next', {
track: {
// Build queue tracks for batch add (V2 handles reverse order)
const queueTracks = playableTracks.map(trk => ({
id: trk.isLocal ? Math.abs(trk.id) : trk.id,
title: trk.title,
artist: trk.artist || 'Unknown Artist',
@@ -1845,17 +1841,18 @@
is_local: trk.isLocal ?? false,
album_id: trk.isLocal ? null : (trk.albumId || null),
artist_id: trk.isLocal ? null : (trk.artistId ?? null),
}
});
} catch (err) {
console.error('Failed to add track next:', err);
}
}
}));
try {
await invoke('v2_add_tracks_to_queue_next', { tracks: queueTracks });
// Tell parent about local tracks added to queue
if (localIds.length > 0) {
onSetLocalQueue?.(localIds);
}
} catch (err) {
console.error('Failed to add tracks next:', err);
}
}
async function handlePlayAllLater() {
@@ -1892,7 +1889,7 @@
.map(trk => Math.abs(trk.id));
try {
await invoke('add_tracks_to_queue', { tracks: queueTracks });
await invoke('v2_add_tracks_to_queue', { tracks: queueTracks });
// Tell parent about local tracks added to queue
if (localIds.length > 0) {
+1 -1
View File
@@ -715,7 +715,7 @@
if (trackResults && trackResults.items.length > 0) {
try {
const queueTracks = buildSearchQueueTracks(trackResults.items);
await invoke('set_queue', { tracks: queueTracks, startIndex: trackIndex });
await invoke('v2_set_queue', { tracks: queueTracks, startIndex: trackIndex });
} catch (err) {
console.error('Failed to set queue:', err);
}
+28 -26
View File
@@ -180,11 +180,11 @@ export async function updateLocalCopiesSet(): Promise<void> {
// ============ Queue Actions ============
/**
* Sync queue state from backend
* Sync queue state from backend (V2)
*/
export async function syncQueueState(): Promise<void> {
try {
const queueState = await invoke<BackendQueueState>('get_queue_state');
const queueState = await invoke<BackendQueueState>('v2_get_queue_state');
// Get track IDs for local copy check
const trackIds = queueState.upcoming.map(t => t.id);
@@ -223,7 +223,7 @@ export async function syncQueueState(): Promise<void> {
}
/**
* Toggle shuffle mode
* Toggle shuffle mode (V2)
*/
export async function toggleShuffle(): Promise<{ success: boolean; enabled: boolean }> {
const newState = !isShuffle;
@@ -231,7 +231,7 @@ export async function toggleShuffle(): Promise<{ success: boolean; enabled: bool
notifyListeners();
try {
await invoke('set_shuffle', { enabled: newState });
await invoke('v2_toggle_shuffle');
return { success: true, enabled: newState };
} catch (err) {
console.error('Failed to set shuffle:', err);
@@ -243,13 +243,15 @@ export async function toggleShuffle(): Promise<{ success: boolean; enabled: bool
}
/**
* Toggle repeat mode (off -> all -> one -> off)
* Toggle repeat mode (off -> all -> one -> off) (V2)
*/
export async function toggleRepeat(): Promise<{ success: boolean; mode: RepeatMode }> {
const nextMode: RepeatMode = repeatMode === 'off' ? 'all' : repeatMode === 'all' ? 'one' : 'off';
// V2 expects capitalized repeat mode: 'Off' | 'All' | 'One'
const v2Mode = nextMode.charAt(0).toUpperCase() + nextMode.slice(1);
try {
await invoke('set_repeat', { mode: nextMode });
await invoke('v2_set_repeat_mode', { mode: v2Mode });
repeatMode = nextMode;
notifyListeners();
return { success: true, mode: nextMode };
@@ -260,11 +262,11 @@ export async function toggleRepeat(): Promise<{ success: boolean; mode: RepeatMo
}
/**
* Add track to play next in queue
* Add track to play next in queue (V2)
*/
export async function addToQueueNext(track: BackendQueueTrack, isLocal = false): Promise<boolean> {
try {
await invoke('add_to_queue_next', { track });
await invoke('v2_add_to_queue_next', { track });
if (isLocal) {
localTrackIds = new Set([...localTrackIds, track.id]);
}
@@ -277,11 +279,11 @@ export async function addToQueueNext(track: BackendQueueTrack, isLocal = false):
}
/**
* Add track to end of queue
* Add track to end of queue (V2)
*/
export async function addToQueue(track: BackendQueueTrack, isLocal = false): Promise<boolean> {
try {
await invoke('add_to_queue', { track });
await invoke('v2_add_to_queue', { track });
if (isLocal) {
localTrackIds = new Set([...localTrackIds, track.id]);
}
@@ -294,11 +296,11 @@ export async function addToQueue(track: BackendQueueTrack, isLocal = false): Pro
}
/**
* Add multiple tracks to queue
* Add multiple tracks to queue (V2)
*/
export async function addTracksToQueue(tracks: BackendQueueTrack[]): Promise<boolean> {
try {
await invoke('add_tracks_to_queue', { tracks });
await invoke('v2_add_tracks_to_queue', { tracks });
await syncQueueState();
return true;
} catch (err) {
@@ -308,11 +310,11 @@ export async function addTracksToQueue(tracks: BackendQueueTrack[]): Promise<boo
}
/**
* Set queue with new tracks
* Set queue with new tracks (V2)
*/
export async function setQueue(tracks: BackendQueueTrack[], startIndex: number, clearLocal = true): Promise<boolean> {
try {
await invoke('set_queue', { tracks, startIndex });
await invoke('v2_set_queue', { tracks, startIndex });
if (clearLocal) {
localTrackIds = new Set();
}
@@ -325,11 +327,11 @@ export async function setQueue(tracks: BackendQueueTrack[], startIndex: number,
}
/**
* Clear the queue
* Clear the queue (V2)
*/
export async function clearQueue(): Promise<boolean> {
try {
await invoke('clear_queue');
await invoke('v2_clear_queue');
queue = [];
queueTotalTracks = 0;
notifyListeners();
@@ -341,11 +343,11 @@ export async function clearQueue(): Promise<boolean> {
}
/**
* Play track at specific index in queue
* Play track at specific index in queue (V2)
*/
export async function playQueueIndex(index: number): Promise<BackendQueueTrack | null> {
try {
return await invoke<BackendQueueTrack | null>('play_queue_index', { index });
return await invoke<BackendQueueTrack | null>('v2_play_queue_index', { index });
} catch (err) {
console.error('Failed to play queue index:', err);
return null;
@@ -353,11 +355,11 @@ export async function playQueueIndex(index: number): Promise<BackendQueueTrack |
}
/**
* Get next track from queue
* Get next track from queue (V2)
*/
export async function nextTrack(): Promise<BackendQueueTrack | null> {
try {
return await invoke<BackendQueueTrack | null>('next_track');
return await invoke<BackendQueueTrack | null>('v2_next_track');
} catch (err) {
console.error('Failed to get next track:', err);
return null;
@@ -365,11 +367,11 @@ export async function nextTrack(): Promise<BackendQueueTrack | null> {
}
/**
* Get previous track from queue
* Get previous track from queue (V2)
*/
export async function previousTrack(): Promise<BackendQueueTrack | null> {
try {
return await invoke<BackendQueueTrack | null>('previous_track');
return await invoke<BackendQueueTrack | null>('v2_previous_track');
} catch (err) {
console.error('Failed to get previous track:', err);
return null;
@@ -377,11 +379,11 @@ export async function previousTrack(): Promise<BackendQueueTrack | null> {
}
/**
* Move a track from one position to another in the queue
* Move a track from one position to another in the queue (V2)
*/
export async function moveQueueTrack(fromIndex: number, toIndex: number): Promise<boolean> {
try {
const success = await invoke<boolean>('move_queue_track', { fromIndex, toIndex });
const success = await invoke<boolean>('v2_move_queue_track', { fromIndex, toIndex });
if (success) {
await syncQueueState();
}
@@ -410,11 +412,11 @@ export function clearLocalTrackIds(): void {
}
/**
* Get the backend queue state (for advanced queue operations)
* Get the backend queue state (for advanced queue operations) (V2)
*/
export async function getBackendQueueState(): Promise<BackendQueueState | null> {
try {
return await invoke<BackendQueueState>('get_queue_state');
return await invoke<BackendQueueState>('v2_get_queue_state');
} catch (err) {
console.error('Failed to get backend queue state:', err);
return null;
+7 -5
View File
@@ -1630,10 +1630,10 @@
}
}
// Remove a track from the upcoming queue by its position in the upcoming list
// Remove a track from the upcoming queue by its position in the upcoming list (V2)
async function handleRemoveFromQueue(upcomingIndex: number) {
try {
await invoke('remove_upcoming_track', { upcomingIndex });
await invoke('v2_remove_upcoming_track', { upcomingIndex });
await syncQueueState(); // Refresh UI
showToast($t('toast.removedFromQueue'), 'info');
} catch (err) {
@@ -1763,7 +1763,7 @@
// Set shuffle mode first
try {
await invoke('set_shuffle', { enabled: true });
await invoke('v2_set_shuffle', { enabled: true });
isShuffle = true;
} catch (err) {
console.error('Failed to enable shuffle:', err);
@@ -2381,10 +2381,12 @@
// Restore shuffle/repeat mode
if (session.shuffle_enabled) {
await invoke('set_shuffle', { enabled: true });
await invoke('v2_set_shuffle', { enabled: true });
}
if (session.repeat_mode !== 'off') {
await invoke('set_repeat', { mode: session.repeat_mode });
// V2 expects capitalized mode: 'Off' | 'All' | 'One'
const v2Mode = session.repeat_mode.charAt(0).toUpperCase() + session.repeat_mode.slice(1);
await invoke('v2_set_repeat_mode', { mode: v2Mode });
}
// Restore volume