fix: reconcile native state on app foreground; refresh playlist after delete

- Call reconcileNativeState() on visibilitychange→visible so the player UI
  updates immediately when the user opens the app after a background auto-advance,
  before deferred evaluateJavascript callbacks have had a chance to fire
- After deleteSong() succeeds, refresh the active playlist view (grid or detail)
  with a 2s delay to let Navidrome's background scan complete

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-29 01:01:56 +02:00
1 parent a2714dddaa
commit 07b8114cae
3 files changed
+32 -2

No files matched your search

+22
View File
@@ -1236,6 +1236,28 @@ if (HAS_BRIDGE) {
}
}
// Immediately sync JS track/play state with the native bridge snapshot.
// Called on app foreground so the UI is correct before any deferred evaluateJavascript callbacks fire.
export function reconcileNativeState() {
if (!HAS_BRIDGE) return;
try {
const snap = JSON.parse(window.NSBridge.getState() || '{}');
const snapId = String(snap.currentId || '');
if (snapId && snapId !== String(S.queue[S.qIdx]?.id || '')) {
const found = S.queue.findIndex(s => String(s.id) === snapId);
if (found >= 0) {
S.qIdx = found;
const s = S.queue[S.qIdx];
if (s) { updatePlayerUI(s, true); syncNowPlaying(); onNpSongChange(s.id); renderQueue(); }
}
}
if (typeof snap.isPlaying === 'boolean' && snap.isPlaying !== _nativePlaying) {
_nativePlaying = snap.isPlaying;
setPlayIcon(snap.isPlaying);
}
} catch {}
}
export function _restoreLastPlayed() {
try {
const saved = JSON.parse(localStorage.getItem('ns_last_played') || 'null');