fix: sync native track index before opening Now Playing overlay
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d0d1b28dc
commit
30ef5300cf
1 file changed
+9
@@ -8,6 +8,15 @@ import { openPlModal, showSongInfo } from './ui.js';
|
|||||||
|
|
||||||
// ─── NOW PLAYING OVERLAY ───
|
// ─── NOW PLAYING OVERLAY ───
|
||||||
export function openNowPlaying() {
|
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;
|
S.npOpen = true;
|
||||||
const overlay = document.getElementById('np-overlay');
|
const overlay = document.getElementById('np-overlay');
|
||||||
overlay.classList.add('open');
|
overlay.classList.add('open');
|
||||||
|
|||||||
Reference in new issue
Block a user