fix #14740: serve playback only to the main window

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hauke
2026-11-10 13:52:26 +01:00
co-authored by Claude Opus 5.5
parent a74cfa5864
commit 8c47388eee
14 changed files with 624 additions and 124 deletions
+41 -13
View File
@@ -1,7 +1,6 @@
<script lang="ts">
import { convertFileSrc } from '@tauri-apps/api/core'
import { onDestroy } from 'svelte'
import { errorText, preparePlayback, type CallId } from './api'
import { errorText, playbackUrl, preparePlayback, releasePlayback, type CallId } from './api'
import { formatOffset } from './format'
let {
@@ -31,6 +30,21 @@
let error = $state('')
/** The mix held in memory where the webview cannot stream it (Linux). */
let blobUrl: string | null = null
/** This player's hold on the mix on disk (see `releasePlayback`). */
let lease: number | null = null
/** Set once the player is gone: a load still under way stops at the next
* step and keeps nothing (no blob, no mix on disk). */
let destroyed = false
const abort = new AbortController()
const LOAD_FAILED = 'Audio konnte nicht geladen werden.'
/** Lets go of the mix on disk (once). */
function release() {
if (lease === null) return
releasePlayback(callId, lease).catch(() => {})
lease = null
}
/** Mixes the call (first use only) and loads the mix into the player. */
function load(): Promise<boolean> {
@@ -38,29 +52,38 @@
preparing = true
error = ''
try {
const info = await preparePlayback(callId)
duration = info.duration_secs
const url = convertFileSrc(info.path)
const prepared = await preparePlayback(callId)
lease = prepared.lease
if (destroyed) return false
duration = prepared.duration_secs
const url = playbackUrl(callId)
try {
await loadSource(url)
} catch (err) {
if (destroyed) return false
if (!(err instanceof MediaError) || err.code !== MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED) {
throw err
}
// WebKitGTK (Linux) plays no media from a custom scheme such as
// asset:// (WebView2 gets http://asset.localhost instead), but
// fetches it fine: there the mix is played from memory.
const response = await fetch(url)
if (!response.ok) throw new Error(`Audio konnte nicht geladen werden (${response.status}).`)
blobUrl = URL.createObjectURL(await response.blob())
// playback:// (WebView2 gets http://playback.localhost instead),
// but fetches it fine: there the mix is played from memory, and
// the file is not needed any more.
const response = await fetch(url, { signal: abort.signal })
if (!response.ok) throw new Error(LOAD_FAILED)
const blob = await response.blob()
if (destroyed) return false
blobUrl = URL.createObjectURL(blob)
release()
await loadSource(blobUrl)
}
return true
return !destroyed
} catch (err) {
error = err instanceof MediaError ? 'Audio konnte nicht geladen werden.' : errorText(err)
if (destroyed) return false
error = err instanceof MediaError ? LOAD_FAILED : errorText(err)
loading = null // a later click tries again
return false
} finally {
if (destroyed) release()
preparing = false
}
})()
@@ -127,11 +150,16 @@
}
onDestroy(() => {
// Lets go of the file, so the call can be deleted right away.
destroyed = true
abort.abort()
// Lets go of the file and the memory, so the call can be deleted right
// away and no customer audio stays behind.
audio?.pause()
audio?.removeAttribute('src')
audio?.load()
if (blobUrl) URL.revokeObjectURL(blobUrl)
blobUrl = null
release()
onplaying?.(false)
})
</script>
+16 -6
View File
@@ -1,6 +1,6 @@
// Typed wrappers around the Tauri commands and events of the app shell.
import { invoke } from '@tauri-apps/api/core'
import { convertFileSrc, invoke } from '@tauri-apps/api/core'
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
export type CallId = number
@@ -142,13 +142,16 @@ export interface CallDetail {
uploading: boolean
/** The call's audio is still on this PC and can be played. */
audio_available: boolean
/** Retention deleted the call's audio (not just: the files are missing). */
audio_deleted: boolean
}
/** A call's two tracks mixed into one file for playback. */
export interface PlaybackInfo {
/** The mixed WAV in the playback cache; play it via `convertFileSrc`. */
path: string
/** A call's two tracks mixed into one file, ready to play from
* `playbackUrl`. */
export interface PreparedPlayback {
duration_secs: number
/** Hand back with `releasePlayback` once the player is done. */
lease: number
}
/** A newer version the release feed offers. */
@@ -199,7 +202,14 @@ export const retryCall = (id: CallId) => invoke<void>('retry_call', { id })
export const discardCall = (id: CallId) => invoke<void>('discard_call', { id })
/** Mixes the call's tracks (or reuses the cached mix); refused while the
* call is recorded or processed and once its audio is gone. */
export const preparePlayback = (id: CallId) => invoke<PlaybackInfo>('prepare_playback', { id })
export const preparePlayback = (id: CallId) =>
invoke<PreparedPlayback>('prepare_playback', { id })
/** The player is done with the mix: it is removed from disk. */
export const releasePlayback = (id: CallId, lease: number) =>
invoke<void>('release_playback', { id, lease })
/** Where the main window plays a prepared mix from (the app's `playback`
* scheme; other windows are refused). */
export const playbackUrl = (id: CallId) => convertFileSrc(String(id), 'playback')
export const listCalls = () => invoke<CallListItem[]>('list_calls')
export const getCall = (id: CallId) => invoke<CallDetail>('get_call', { id })
/** An empty name restores the default label. */
+10 -3
View File
@@ -166,9 +166,12 @@
}),
]
refreshList()
// Read on every visit: the settings page is a route of this window, so
// a changed retention period is shown on the way back. Without it the
// "no audio" line just leaves the period out.
getSettings()
.then((settings) => (retentionDays = settings.retention_days))
.catch(() => {})
.catch((err) => console.warn('settings not read:', errorText(err)))
getRecordingState()
.then((state) => (recordingState = state))
.catch((err) => (recordError = errorText(err)))
@@ -514,11 +517,15 @@
>
{/if}
</div>
{:else}
{:else if detail.audio_deleted && retentionDays !== null}
<p class="muted no-audio">
Audio nicht mehr vorhanden – Aufnahmen werden {retentionDays ?? '…'} Tage nach der
Audio nicht mehr vorhanden – Aufnahmen werden {retentionDays} Tage nach der
Transkription gelöscht (<a href="#/settings">Einstellungen</a>).
</p>
{:else if detail.audio_deleted}
<p class="muted no-audio">Audio nicht mehr vorhanden.</p>
{:else}
<p class="muted no-audio">Audio nicht vorhanden.</p>
{/if}
{/if}