From 30ef5300cf1c829ddc5b77ae290c7589e0808f25 Mon Sep 17 00:00:00 2001 From: Honey Date: Thu, 14 May 2026 19:49:05 +0200 Subject: [PATCH] fix: sync native track index before opening Now Playing overlay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Android, onTrackChanged fires asynchronously so opening the overlay quickly after a track change could show the previous song. Query NSBridge.getState() synchronously at open time to get the real index. Same flash can also occur on web — openNowPlaying now always renders from current S.qIdx. Co-Authored-By: Claude Sonnet 4.6 --- src/nowplaying.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/nowplaying.js b/src/nowplaying.js index 67b0c15..0bc6cba 100644 --- a/src/nowplaying.js +++ b/src/nowplaying.js @@ -8,6 +8,15 @@ import { openPlModal, showSongInfo } from './ui.js'; // ─── NOW PLAYING OVERLAY ─── export function openNowPlaying() { + // On Android, onTrackChanged is async — query native for the current index + // before rendering so we never show the previous song for a flash. + if (typeof window.NSBridge !== 'undefined') { + try { + const state = JSON.parse(window.NSBridge.getState() || '{}'); + if (typeof state.currentIndex === 'number' && state.currentIndex >= 0 && state.currentIndex < S.queue.length) + S.qIdx = state.currentIndex; + } catch {} + } S.npOpen = true; const overlay = document.getElementById('np-overlay'); overlay.classList.add('open');