From 3c123958caad35cdc50818fb3b7cb6c728def66e Mon Sep 17 00:00:00 2001 From: BoulderBadgeDad Date: Sat, 30 May 2026 14:45:39 -0700 Subject: [PATCH] Fix: Artist Radio never populated the queue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit playArtistRadio() flipped npRadioMode=true directly but never fetched similar tracks, so the queue stayed empty until the current song ENDED (onAudioEnded is what triggered the radio fetch). The modal's Radio button does it right via npSetRadioMode(true, {fetchIfNeeded:true}). Fix: await playLibraryTrack(...) (it's async and sets currentTrack only after resolving the canonical DB row), THEN call npSetRadioMode(true, {fetchIfNeeded}) — which seeds the current track into the queue and immediately fetches the radio queue. Replaces the old fixed-setTimeout guess that raced the async track load (and could fire before currentTrack.id existed -> silent no-op). --- webui/static/stats-automations.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/webui/static/stats-automations.js b/webui/static/stats-automations.js index daab421e..37f1d51d 100644 --- a/webui/static/stats-automations.js +++ b/webui/static/stats-automations.js @@ -4740,9 +4740,12 @@ async function playArtistRadio() { audioPlayer.pause(); } - // Play the track first, then enable radio mode after a short delay - // so currentTrack is set and the radio queue fill triggers - playLibraryTrack({ + // Play the track and WAIT for it to resolve (playLibraryTrack is async + // and fetches the canonical DB row before setting currentTrack) — so + // currentTrack.id is reliably set before we fetch the radio queue. A + // fixed setTimeout raced this and often fired before the id existed, + // leaving the queue empty until the song ended. + await playLibraryTrack({ id: random.track.id, title: random.track.title, file_path: random.track.file_path, @@ -4751,12 +4754,14 @@ async function playArtistRadio() { album_id: random.album.id, }, random.album.title || '', artistName); - // Enable radio mode after track starts loading - setTimeout(() => { + // Enable radio mode + immediately seed the queue with similar tracks — + // same path the modal's Radio button uses (fetchIfNeeded also adds the + // current track to the queue first). + if (typeof npSetRadioMode === 'function') { + npSetRadioMode(true, { toast: false, fetchIfNeeded: true }); + } else { npRadioMode = true; - const radioBtn = document.querySelector('.np-radio-btn'); - if (radioBtn) radioBtn.classList.add('active'); - }, 1000); + } showToast(`Playing ${artistName} radio — similar tracks will auto-queue`, 'success'); } catch (e) {