get the encoder work off the main thread and harden the update path
This commit is contained in:
+28
-37
@@ -149,38 +149,34 @@
|
||||
})
|
||||
|
||||
onMount(() => {
|
||||
let unlistenHotkey: (() => void) | null = null
|
||||
let unlistenProgress: (() => void) | null = null
|
||||
let unlistenAudio: (() => void) | null = null
|
||||
let unlistenAudioRecovered: (() => void) | null = null
|
||||
let unlistenOverlayClosed: (() => void) | null = null
|
||||
const unlisten: (() => void)[] = []
|
||||
// Registered one at a time rather than through a single Promise.all: one
|
||||
// rejected registration used to lose the whole batch, which left every
|
||||
// listener live and none of them removable - hotkeys included.
|
||||
const keep = (p: Promise<() => void>) => {
|
||||
void p.then(fn => unlisten.push(fn))
|
||||
.catch(e => console.warn("could not register a listener:", e))
|
||||
}
|
||||
|
||||
keep(listen("overlay-closed", () => { useFrame = false }))
|
||||
keep(api.onHotkey((kind) => {
|
||||
if (kind === "start" && phase === "idle") void startRec()
|
||||
else if (kind === "pause") {
|
||||
if (phase === "recording") void pauseRec()
|
||||
else if (phase === "paused") void resumeRec()
|
||||
} else if (kind === "stop") {
|
||||
if (phase === "recording" || phase === "paused") void stopRec()
|
||||
}
|
||||
}))
|
||||
keep(api.onEncodeProgress((p) => {
|
||||
encodeProgress = { pass: p.pass, total: p.total_passes, pct: p.percent }
|
||||
}))
|
||||
keep(api.onAudioFailed((msg) => {
|
||||
audioWarning = msg || "audio capture failed - audio will not be recorded"
|
||||
}))
|
||||
keep(listen("audio-recovered", () => { audioWarning = null }))
|
||||
|
||||
void (async () => {
|
||||
const [overlayClosed, hotkey, progress, audio, audioRecovered] = await Promise.all([
|
||||
listen("overlay-closed", () => { useFrame = false }),
|
||||
api.onHotkey((kind) => {
|
||||
if (kind === "start" && phase === "idle") void startRec()
|
||||
else if (kind === "pause") {
|
||||
if (phase === "recording") void pauseRec()
|
||||
else if (phase === "paused") void resumeRec()
|
||||
} else if (kind === "stop") {
|
||||
if (phase === "recording" || phase === "paused") void stopRec()
|
||||
}
|
||||
}),
|
||||
api.onEncodeProgress((p) => {
|
||||
encodeProgress = { pass: p.pass, total: p.total_passes, pct: p.percent }
|
||||
}),
|
||||
api.onAudioFailed((msg) => {
|
||||
audioWarning = msg || "audio capture failed - audio will not be recorded"
|
||||
}),
|
||||
listen("audio-recovered", () => { audioWarning = null }),
|
||||
])
|
||||
unlistenOverlayClosed = overlayClosed
|
||||
unlistenHotkey = hotkey
|
||||
unlistenProgress = progress
|
||||
unlistenAudio = audio
|
||||
unlistenAudioRecovered = audioRecovered
|
||||
|
||||
try {
|
||||
config = await api.getConfig()
|
||||
format = config.export.default_format
|
||||
@@ -191,13 +187,8 @@
|
||||
console.warn("failed to load config:", e)
|
||||
}
|
||||
})()
|
||||
return () => {
|
||||
unlistenHotkey?.()
|
||||
unlistenProgress?.()
|
||||
unlistenAudio?.()
|
||||
unlistenAudioRecovered?.()
|
||||
unlistenOverlayClosed?.()
|
||||
}
|
||||
|
||||
return () => { unlisten.forEach(fn => fn()) }
|
||||
})
|
||||
|
||||
// ---- Actions ----
|
||||
|
||||
Reference in New Issue
Block a user