refactor: dedup buildTrackList, extract topsong row helper, split romaji to lib

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-21 11:36:06 +02:00
1 parent 84f1fd006d
commit b9a5c6468f
4 files changed
+162 -171

No files matched your search

+7 -17
View File
@@ -46,9 +46,9 @@ function _nsBridge(method, ...args) {
try { window.NSBridge[method](...args); } catch(_) {}
}
// Build the NSBridge Track JSON array from S.queue.
function buildTrackList() {
return S.queue.map(s => ({
// Convert a single Navidrome song to the NSBridge Track schema.
function _trackToNative(s) {
return {
id: s.id,
url: streamUrl(s.id),
title: s.title || '',
@@ -56,9 +56,12 @@ function buildTrackList() {
album: s.album || null,
artworkUrl: s.coverArt ? coverUrl(s.coverArt, 1024) : null,
durationMs: Math.floor((s.duration || 0) * 1000),
}));
};
}
// Build the NSBridge Track JSON array from S.queue.
const buildTrackList = () => S.queue.map(_trackToNative);
// Push the current JS queue to native whenever S.queue changes (radio top-ups, etc.).
function _pushQueueIfBridge() {
if (!HAS_BRIDGE) return;
@@ -73,19 +76,6 @@ export function nativeInsertAt(song, position) {
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 {
id: s.id,
url: streamUrl(s.id),
title: s.title || '',
artist: s.artist || '',
album: s.album || null,
artworkUrl: s.coverArt ? coverUrl(s.coverArt, 1024) : null,
durationMs: Math.floor((s.duration || 0) * 1000),
};
}
// ─── NATIVE → JS CALLBACKS ────────────────────────────────────────────────
// window.NSPlayer is the surface that MusicService calls back into.
// Installed here so it exists before onPageFinished fires.