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]) },