Fix critical shuffle queue bug, Local Library context, and sample rate crash
1. QUEUE SHUFFLE FIX (CRITICAL): - When shuffle enabled and set_queue called, starting track was placed randomly in shuffle_order - This caused queue UI to show only tracks AFTER that random position - Example: 11 tracks, start at index 5, but index 5 was at position 7 in shuffle → only 3 tracks visible - FIX: When shuffle enabled, swap starting track to position 0 in shuffle_order - Now all tracks appear in queue UI as expected 2. LOCAL LIBRARY CONTEXT FIX: - handleLocalTrackPlay was clearing context immediately after LocalLibraryView set it - FIX: Removed clearPlaybackContext() call - LocalLibraryView handles context correctly - Context icon should now display for Local Library playback 3. SAMPLE RATE CRASH FIX: - show_track_notification expected u32 but received f64 (44.1, 88.2, etc.) - Error: "invalid type: floating point 44.1, expected u32" - FIX: Changed sample_rate parameter from u32 to f64 in notification command and format_quality - Bonus: Format shows "44.1" for fractional rates, "48" for whole numbers Files modified: - src-tauri/src/queue/mod.rs - Fixed set_queue to move start_index to front of shuffle_order - src/routes/+page.svelte - Removed clearPlaybackContext from handleLocalTrackPlay - src-tauri/src/commands/notification.rs - Changed sample_rate to f64 with proper formatting
This commit is contained in:
1 parent
3d8c049226
commit
61fa05da93
3 files changed
+41
-6
No files matched your search
@@ -76,13 +76,24 @@ fn resolve_local_artwork(url: &str) -> Option<PathBuf> {
|
||||
}
|
||||
|
||||
/// Format quality info for notification
|
||||
fn format_quality(bit_depth: Option<u32>, sample_rate: Option<u32>) -> String {
|
||||
fn format_quality(bit_depth: Option<u32>, sample_rate: Option<f64>) -> String {
|
||||
match (bit_depth, sample_rate) {
|
||||
(Some(bits), Some(rate)) if bits >= 24 || rate > 48 => {
|
||||
format!("Hi-Res • {}-bit/{}kHz", bits, rate)
|
||||
(Some(bits), Some(rate)) if bits >= 24 || rate > 48.0 => {
|
||||
// Format sample rate: 44.1 → 44.1, 48.0 → 48, 192.0 → 192
|
||||
let rate_str = if rate.fract() == 0.0 {
|
||||
format!("{}", rate as u32)
|
||||
} else {
|
||||
format!("{}", rate)
|
||||
};
|
||||
format!("Hi-Res • {}-bit/{}kHz", bits, rate_str)
|
||||
}
|
||||
(Some(bits), Some(rate)) => {
|
||||
format!("CD Quality • {}-bit/{}kHz", bits, rate)
|
||||
let rate_str = if rate.fract() == 0.0 {
|
||||
format!("{}", rate as u32)
|
||||
} else {
|
||||
format!("{}", rate)
|
||||
};
|
||||
format!("CD Quality • {}-bit/{}kHz", bits, rate_str)
|
||||
}
|
||||
_ => String::new()
|
||||
}
|
||||
@@ -96,7 +107,7 @@ pub fn show_track_notification(
|
||||
album: String,
|
||||
artwork_url: Option<String>,
|
||||
bit_depth: Option<u32>,
|
||||
sample_rate: Option<u32>,
|
||||
sample_rate: Option<f64>, // Changed from u32 to f64 to support 44.1, 88.2, 176.4, etc.
|
||||
) -> Result<(), String> {
|
||||
log::info!("Command: show_track_notification - {} by {}", title, artist);
|
||||
|
||||
|
||||
@@ -164,6 +164,29 @@ impl QueueManager {
|
||||
|
||||
// Regenerate shuffle order
|
||||
Self::regenerate_shuffle_order_internal(&mut state);
|
||||
|
||||
// CRITICAL FIX: When shuffle is enabled and we have a start_index,
|
||||
// ensure the start_index track is at the BEGINNING of shuffle order
|
||||
// This fixes the bug where shuffle shows incomplete queue
|
||||
if state.shuffle {
|
||||
if let Some(start_idx) = start_index {
|
||||
if start_idx < state.tracks.len() {
|
||||
// Find where start_idx is in the current shuffle_order
|
||||
if let Some(pos) = state.shuffle_order.iter().position(|&x| x == start_idx) {
|
||||
// Move it to the front by swapping
|
||||
state.shuffle_order.swap(0, pos);
|
||||
// Set shuffle position to 0 so we start from the beginning
|
||||
state.shuffle_position = 0;
|
||||
|
||||
log::info!(
|
||||
"Queue: Adjusted shuffle order to start with track index {} (was at position {})",
|
||||
start_idx,
|
||||
pos
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear the queue
|
||||
|
||||
@@ -1363,7 +1363,8 @@
|
||||
|
||||
async function handleLocalTrackPlay(track: LocalLibraryTrack) {
|
||||
console.log('Playing local track:', track);
|
||||
await clearPlaybackContext();
|
||||
// DO NOT clear context - LocalLibraryView already sets it correctly
|
||||
// await clearPlaybackContext();
|
||||
|
||||
const artwork = track.artwork_path ? convertFileSrc(track.artwork_path) : '';
|
||||
const quality = track.bit_depth && track.sample_rate
|
||||
|
||||
Reference in new issue
Block a user