From 68bec678808d4cf718c52da3acbecedba2d7935b Mon Sep 17 00:00:00 2001 From: Honey Date: Mon, 18 May 2026 22:27:25 +0200 Subject: [PATCH] fix: sync queue insert/append to native Android player MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both 'Als Nächstes einfügen' and 'Am Ende der Queue' updated S.queue in JS but never called NSBridge, so the native ExoPlayer ignored the change and kept playing the original next item. - Export nativeInsertAt(song, position) from player.js - Call it in showCtxMenu with the exact splice index for insert-next and -1 (append) for add-to-end Co-Authored-By: Claude Sonnet 4.6 --- src/player.js | 6 ++++++ src/ui.js | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/player.js b/src/player.js index c208947..ee4c1bc 100644 --- a/src/player.js +++ b/src/player.js @@ -49,6 +49,12 @@ function _pushQueueIfBridge() { } catch (e) { console.warn('NSBridge.setQueue failed', e); } } +// Insert a single song into the native queue at the given index (-1 = append). +export function nativeInsertAt(song, position) { + if (!HAS_BRIDGE) return; + try { window.NSBridge.addToQueue(JSON.stringify(_trackToNative(song)), position); } catch(_) {} +} + // Convert a single Navidrome song to the NSBridge Track schema (used for addToQueue). function _trackToNative(s) { return { diff --git a/src/ui.js b/src/ui.js index 3f433d6..7d7dfbf 100644 --- a/src/ui.js +++ b/src/ui.js @@ -3,7 +3,7 @@ import { esc, formatDur, toast } from './utils.js'; import { api, coverUrl, ndAuth } from './api.js'; import { THEMES, applyTheme, getCurrentThemeId } from './themes.js'; // Circular imports — safe (only used inside function bodies) -import { playQueue, dlSongLocal, toggleStar, togglePlay, renderQueue, syncNpStar, updateStarBtn, npToggleStar, playCurrent, _syncNpDirect, setPlayIcon } from './player.js'; +import { playQueue, dlSongLocal, toggleStar, togglePlay, renderQueue, syncNpStar, updateStarBtn, npToggleStar, playCurrent, _syncNpDirect, setPlayIcon, nativeInsertAt } from './player.js'; import { navigate, loadPlaylists } from './views.js'; // ─── SIDEBAR ─── @@ -115,11 +115,15 @@ export function showCtxMenu(e, song, list, idx) { const items = [ { icon: '▶', label: 'Abspielen', fn: () => playQueue(list, idx) }, { icon: '+', label: 'Als Nächstes einfügen', fn: () => { - S.queue.splice(S.qIdx+1, 0, {...song}); + const insertIdx = S.qIdx + 1; + S.queue.splice(insertIdx, 0, {...song}); + nativeInsertAt(song, insertIdx); renderQueue(); toast('In Warteschlange eingefügt'); }}, { icon: '⬇', label: 'Am Ende der Queue', fn: () => { - S.queue.push({...song}); renderQueue(); toast('Zur Queue hinzugefügt'); + S.queue.push({...song}); + nativeInsertAt(song, -1); + renderQueue(); toast('Zur Queue hinzugefügt'); }}, { sep: true }, { icon: '🎶', label: 'Zu Playlist hinzufügen →', submenu: true, fn: () => openPlModal([song]) },