diff --git a/crates/qbz-core/src/core.rs b/crates/qbz-core/src/core.rs index c38e96cef..5de23b833 100644 --- a/crates/qbz-core/src/core.rs +++ b/crates/qbz-core/src/core.rs @@ -127,6 +127,12 @@ impl QbzCore { queue.get_state() } + /// Get all queue tracks and current index (for session persistence) + pub async fn get_all_queue_tracks(&self) -> (Vec, Option) { + let queue = self.queue.read().await; + queue.get_all_tracks() + } + /// Set repeat mode pub async fn set_repeat_mode(&self, mode: RepeatMode) { let queue = self.queue.write().await; diff --git a/crates/qbz-player/src/queue.rs b/crates/qbz-player/src/queue.rs index 2a22da35d..6069b5a80 100644 --- a/crates/qbz-player/src/queue.rs +++ b/crates/qbz-player/src/queue.rs @@ -653,6 +653,13 @@ impl QueueManager { } } + /// Get all tracks in the queue plus the current index (for session persistence). + /// Unlike get_state() which caps upcoming/history, this returns the full track list. + pub fn get_all_tracks(&self) -> (Vec, Option) { + let state = self.state.lock().unwrap(); + (state.tracks.clone(), state.current_index) + } + /// Regenerate shuffle order (internal, must be called with lock held) fn regenerate_shuffle_order_internal(state: &mut InternalState) { let mut order: Vec = (0..state.tracks.len()).collect(); diff --git a/src-tauri/src/commands_v2.rs b/src-tauri/src/commands_v2.rs index 473c5fb57..a492a1fab 100644 --- a/src-tauri/src/commands_v2.rs +++ b/src-tauri/src/commands_v2.rs @@ -4360,6 +4360,15 @@ pub async fn v2_get_queue_state( Ok(bridge.get_queue_state().await) } +/// Get all queue tracks and current index (for session persistence, no caps) +#[tauri::command] +pub async fn v2_get_all_queue_tracks( + bridge: State<'_, CoreBridgeState>, +) -> Result<(Vec, Option), RuntimeError> { + let bridge = bridge.get().await; + Ok(bridge.get_all_queue_tracks().await) +} + /// Get currently selected queue track (V2) #[tauri::command] pub async fn v2_get_current_queue_track( diff --git a/src-tauri/src/core_bridge.rs b/src-tauri/src/core_bridge.rs index e329327a4..8725b3aae 100644 --- a/src-tauri/src/core_bridge.rs +++ b/src-tauri/src/core_bridge.rs @@ -106,6 +106,11 @@ impl CoreBridge { self.core.get_queue_state().await } + /// Get all queue tracks and current index (for session persistence) + pub async fn get_all_queue_tracks(&self) -> (Vec, Option) { + self.core.get_all_queue_tracks().await + } + /// Set repeat mode pub async fn set_repeat_mode(&self, mode: RepeatMode) { self.core.set_repeat_mode(mode).await diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d7d84df14..2f0ad98dc 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -932,6 +932,7 @@ pub fn run() { commands_v2::v2_set_force_x11, commands_v2::v2_restart_app, commands_v2::v2_get_queue_state, + commands_v2::v2_get_all_queue_tracks, commands_v2::v2_get_current_queue_track, commands_v2::v2_set_repeat_mode, commands_v2::v2_toggle_shuffle, diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index b300b5e15..4472e6ad1 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2664,37 +2664,27 @@ } } - // Get current queue state from backend (may be empty) - const queueState = await getBackendQueueState(); + // Get ALL queue tracks from backend (uncapped, for full persistence) + const [tracks, currentIndex] = await invoke<[BackendQueueTrack[], number | null]>('v2_get_all_queue_tracks'); - // Build persisted queue tracks - const allTracks: PersistedQueueTrack[] = []; - if (queueState?.current_track) { - allTracks.push({ - id: queueState.current_track.id, - title: queueState.current_track.title, - artist: queueState.current_track.artist, - album: queueState.current_track.album, - duration_secs: queueState.current_track.duration_secs, - artwork_url: queueState.current_track.artwork_url - }); - } - if (queueState?.upcoming) { - for (const track of queueState.upcoming) { - allTracks.push({ - id: track.id, - title: track.title, - artist: track.artist, - album: track.album, - duration_secs: track.duration_secs, - artwork_url: track.artwork_url - }); - } - } + const allTracks: PersistedQueueTrack[] = tracks.map(track => ({ + id: track.id, + title: track.title, + artist: track.artist, + album: track.album, + duration_secs: track.duration_secs, + artwork_url: track.artwork_url, + hires: track.hires, + bit_depth: track.bit_depth ?? null, + sample_rate: track.sample_rate ?? null, + is_local: track.is_local ?? false, + album_id: track.album_id ?? null, + artist_id: track.artist_id ?? null, + })); await saveSessionState( allTracks, - queueState?.current_index ?? null, + currentIndex, currentTrack ? Math.floor(currentTime) : 0, volume / 100, isShuffle,