fix: resolve queue_item_id from track_id, fix loadQconnectQueue, push queue on connect

Three fixes for QConnect seekbar and queue sync:

1. Position reports now include currentTrackId from frontend. Backend
   looks up queue_item_id by matching track_id against QConnect queue
   state when renderer sync state has no cached value. This resolves
   the root cause of seekbar showing position 0 on controllers.

2. loadQconnectQueue changed from fire-and-forget (void) to proper
   error handling with logging at every step. Added logging before
   isQconnectConnected check to diagnose silent failures.

3. When TransportConnected event fires while QBZ is already playing,
   automatically push the local queue to QConnect server so controllers
   immediately see the correct tracks.
This commit is contained in:
vicrodh committed 2026-02-22 14:01:42 -06:00
1 parent db0360f4e0
commit 8f2fd7cf1a
3 files changed
+95 -6

No files matched your search

+5 -1
View File
@@ -415,8 +415,12 @@ export async function loadQconnectQueue(
startIndex: number = 0,
shuffleMode: boolean = false
): Promise<boolean> {
console.log('[QConnect/LoadQueue] called: trackCount=%d startIndex=%d', trackIds.length, startIndex);
const qconnectConnected = await isQconnectConnected();
if (!qconnectConnected) return false;
if (!qconnectConnected) {
console.warn('[QConnect/LoadQueue] skipped: transport not connected');
return false;
}
const origin: QconnectTrackOrigin = 'qobuz_online';
const admission = await evaluateQconnectAdmission(origin);
+31 -4
View File
@@ -1260,7 +1260,10 @@
// Sync the full queue to QConnect remote so controllers see the album
const trackIds = album.tracks.map(trk => trk.id);
void loadQconnectQueue(trackIds, 0);
loadQconnectQueue(trackIds, 0).then(ok => {
if (ok) console.log('[QConnect] Album queue synced to remote (%d tracks)', trackIds.length);
else console.warn('[QConnect] Album queue NOT synced to remote (not connected or rejected)');
}).catch(err => console.error('[QConnect] Album queue sync error:', err));
const firstTrack = album.tracks[0];
const quality = firstTrack.hires && firstTrack.bitDepth && firstTrack.samplingRate
@@ -1480,7 +1483,10 @@
// Sync the full queue to QConnect remote so controllers see the playlist
const trackIds = tracks.map(trk => trk.id);
void loadQconnectQueue(trackIds, 0);
loadQconnectQueue(trackIds, 0).then(ok => {
if (ok) console.log('[QConnect] Playlist queue synced to remote (%d tracks)', trackIds.length);
else console.warn('[QConnect] Playlist queue NOT synced to remote (not connected or rejected)');
}).catch(err => console.error('[QConnect] Playlist queue sync error:', err));
const firstTrack = tracks[0];
const artwork = firstTrack.album?.image?.large || firstTrack.album?.image?.thumbnail || firstTrack.album?.image?.small || '';
@@ -3198,6 +3204,7 @@
duration: durationMs,
currentQueueItemId: null,
nextQueueItemId: null,
currentTrackId: currentTrack?.id ?? null,
}).catch(() => {});
}
}, 2000);
@@ -3402,6 +3409,7 @@
duration: durationMs,
currentQueueItemId: null,
nextQueueItemId: null,
currentTrackId: currentTrack?.id ?? null,
}).catch(() => {});
}
}
@@ -3728,10 +3736,29 @@
pushQobuzConnectDiagnostic('qconnect:event', 'info', event.payload);
void refreshQobuzConnectRuntimeState();
// Sync QBZ local queue when QConnect remote queue changes or
// renderer commands move the current track (next/prev from controllers).
const payload = event.payload as Record<string, unknown> | null;
if (payload) {
// When QConnect connects while QBZ is already playing, push the current
// queue to the server so controllers immediately see the right tracks.
if ('TransportConnected' in payload) {
console.log('[QConnect] TransportConnected detected, checking if local queue should be pushed');
if (isPlaying && currentTrack) {
const queueState = getQueueState();
const trackIds = queueState.queue
.map(item => item.trackId)
.filter((id): id is number => typeof id === 'number' && id > 0);
if (trackIds.length > 0) {
console.log('[QConnect] Pushing local queue to remote on connect (%d tracks)', trackIds.length);
loadQconnectQueue(trackIds, 0).then(ok => {
if (ok) console.log('[QConnect] Local queue pushed to remote on connect');
else console.warn('[QConnect] Local queue NOT pushed on connect (rejected or failed)');
}).catch(err => console.error('[QConnect] Local queue push on connect error:', err));
}
}
}
// Sync QBZ local queue when QConnect remote queue changes or
// renderer commands move the current track (next/prev from controllers).
const needsQueueSync =
'QueueUpdated' in payload ||
'RendererCommandApplied' in payload ||