fix(session): save full queue with all tracks and metadata
The save was broken in two ways: 1. Only current_track + upcoming (capped at 20) were saved, dropping all history tracks. Queue was reconstructed incomplete on restore. 2. Track metadata (hires, bit_depth, sample_rate, source, etc.) was not being persisted, only the basic 6 fields. Add v2_get_all_queue_tracks command that returns the full uncapped track list with correct current_index. Use it in saveSessionBeforeClose instead of the capped v2_get_queue_state. Map all metadata fields.
This commit is contained in:
6 files changed
+45
-27
No files matched your search
@@ -127,6 +127,12 @@ impl<A: FrontendAdapter + Send + Sync + 'static> QbzCore<A> {
|
||||
queue.get_state()
|
||||
}
|
||||
|
||||
/// Get all queue tracks and current index (for session persistence)
|
||||
pub async fn get_all_queue_tracks(&self) -> (Vec<QueueTrack>, Option<usize>) {
|
||||
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;
|
||||
|
||||
@@ -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<QueueTrack>, Option<usize>) {
|
||||
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<usize> = (0..state.tracks.len()).collect();
|
||||
|
||||
@@ -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<CoreQueueTrack>, Option<usize>), 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(
|
||||
|
||||
@@ -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<qbz_models::playback::QueueTrack>, Option<usize>) {
|
||||
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
|
||||
|
||||
@@ -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,
|
||||
|
||||
+17
-27
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user