Implemented standalone builds

This commit is contained in:
Ben committed 2026-07-05 09:24:07 +02:00
1 parent 43213f6220
commit f1c8e2c575
37 files changed
+5771 -10

No files matched your search

+17 -5
View File
@@ -158,14 +158,24 @@ export interface SaveResult {
playlists: number
}
// API origin. In the packaged desktop app the frontend is served from
// tauri://localhost, so it can't use relative /api paths — the Tauri shell
// injects window.__KONDUKTOR_API__ (the sidecar's http://127.0.0.1:<port>)
// before any app script runs. In the browser dev server it's undefined, so we
// fall back to relative URLs and let Vite proxy /api to the backend.
export const API_BASE: string =
(typeof window !== 'undefined' &&
(window as unknown as { __KONDUKTOR_API__?: string }).__KONDUKTOR_API__) ||
''
async function getJSON<T>(url: string): Promise<T> {
const res = await fetch(url)
const res = await fetch(API_BASE + url)
if (!res.ok) throw new Error(`${res.status} ${res.statusText} — ${url}`)
return res.json() as Promise<T>
}
async function send<T>(method: string, url: string, body?: unknown): Promise<T> {
const res = await fetch(url, {
const res = await fetch(API_BASE + url, {
method,
headers: body ? { 'Content-Type': 'application/json' } : undefined,
body: body ? JSON.stringify(body) : undefined,
@@ -233,8 +243,10 @@ export const api = {
save: () => send<SaveResult>('POST', '/api/save'),
editTrack: (trackId: string, fields: Record<string, string | number | null>) =>
send<{ status: string }>('PATCH', '/api/tracks', { track_id: trackId, fields }),
artUrl: (trackId: string) => `/api/tracks/art?track_id=${encodeURIComponent(trackId)}`,
audioUrl: (trackId: string) => `/api/tracks/audio?track_id=${encodeURIComponent(trackId)}`,
artUrl: (trackId: string) =>
`${API_BASE}/api/tracks/art?track_id=${encodeURIComponent(trackId)}`,
audioUrl: (trackId: string) =>
`${API_BASE}/api/tracks/audio?track_id=${encodeURIComponent(trackId)}`,
trackCues: (trackId: string) =>
getJSON<TrackCues>(`/api/tracks/cues?track_id=${encodeURIComponent(trackId)}`),
createHotcue: (trackId: string, slot: number, start: number, type: number, length = 0) =>
@@ -262,7 +274,7 @@ export const api = {
const fd = new FormData()
fd.append('track_id', trackId)
fd.append('file', file)
const res = await fetch('/api/tracks/art', { method: 'PUT', body: fd })
const res = await fetch(`${API_BASE}/api/tracks/art`, { method: 'PUT', body: fd })
if (!res.ok) throw new Error(`Cover upload failed (${res.status})`)
return res.json()
},
+16
View File
@@ -82,6 +82,22 @@ export function PrepStrip({ track, playRequest = 0, onError }: Props) {
return audioCtxRef.current
}
// Tear everything down when the strip itself unmounts (e.g. the collection
// picker early-returns and replaces the whole UI). Without this, the playback
// source keeps running in an AudioContext that's never closed, so a fresh
// remount plays a SECOND track on top of the orphaned one. Closing both
// contexts is the surefire kill; runs once, on unmount.
useEffect(() => {
return () => {
playbackRef.current?.pause()
scratchRef.current?.dispose()
void audioCtxRef.current?.close()
void scratchCtxRef.current?.close()
audioCtxRef.current = null
scratchCtxRef.current = null
}
}, [])
// The scratch engine gets its OWN AudioContext: a ScriptProcessorNode is
// unreliable sharing a context with the playback source node (it goes silent
// once a source has played), so we keep them fully separate.