stop settings from stranding a recording and losing its own state

This commit is contained in:
2026-09-21 06:18:50 +03:00
parent c9ee532bd3
commit 371c910068
4 changed files with 27 additions and 7 deletions
+4 -3
View File
@@ -10,15 +10,16 @@
async function start() {
phase = "downloading"; errMsg = null; progress = null
const unlisten = await api.onFfmpegProgress((p) => { progress = p })
let unlisten: (() => void) | null = null
try {
unlisten = await api.onFfmpegProgress((p) => { progress = p })
await api.downloadFfmpeg()
unlisten()
onReady()
} catch (e) {
unlisten()
errMsg = String(e)
phase = "error"
} finally {
unlisten?.()
}
}
</script>
+7
View File
@@ -11,6 +11,11 @@
let warnings: string[] = $state([])
async function save() {
const keys = [start, stop, pause].filter(Boolean)
if (new Set(keys).size !== keys.length) {
warnings = ['Multiple actions assigned to the same key - each hotkey must be unique']
return
}
saving = true
warnings = []
try {
@@ -28,6 +33,8 @@
} else {
onDone()
}
} catch (e) {
warnings = [String(e)]
} finally { saving = false }
}
+12 -2
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { onMount } from "svelte"
import { onDestroy, onMount } from "svelte"
import { api, formatBytes, type Config, type Format, type GifBudgetMode, type GifDither, type RecordedClip, type ExportResult, type CaptureRect } from "./api"
import { save } from "@tauri-apps/plugin-dialog"
import { emit, listen } from "@tauri-apps/api/event"
@@ -385,6 +385,13 @@
function tick() { elapsedTimer = window.setInterval(() => { elapsed += 0.1 }, 100) }
function clearTick() { if (elapsedTimer !== null) { clearInterval(elapsedTimer); elapsedTimer = null } }
onDestroy(clearTick)
// The settings view replaces Main, which would strand a running capture or
// encode with no UI left to stop it, so the button stays locked while one is
// live.
const BUSY_PHASES: Phase[] = ["recording", "paused", "exporting"]
let settingsLocked = $derived(BUSY_PHASES.includes(phase))
// Reactivity
$effect(() => {
@@ -473,7 +480,8 @@
{/if}
</div>
<div class="topbar-right">
<button class="icon-btn" onclick={onSettings} aria-label="settings" title="settings">
<button class="icon-btn" onclick={onSettings} aria-label="settings" disabled={settingsLocked}
title={settingsLocked ? "stop the current recording or export first" : "settings"}>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="8" cy="8" r="2"/>
<path d="M8 1v2M8 13v2M1 8h2M13 8h2M3.3 3.3l1.4 1.4M11.3 11.3l1.4 1.4M3.3 12.7l1.4-1.4M11.3 4.7l1.4-1.4"/>
@@ -806,6 +814,8 @@
transition: color 80ms, border-color 80ms, background 80ms;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-2); background: var(--bg-3); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn:disabled:hover { color: var(--text-3); border-color: var(--border); background: transparent; }
/* ---- Main ---- */
.main {
+4 -2
View File
@@ -45,7 +45,7 @@
onMount(async () => {
cfg = await api.getConfig()
initialCfg = structuredClone(cfg)
initialCfg = $state.snapshot(cfg)
try { codecs = await api.codecAvailability() } catch { codecs = null }
})
@@ -84,9 +84,11 @@
if (failed.length > 0) {
hotkeyWarnings = [`${failed.join(", ")} - hotkey may be in use by another app`]
} else {
initialCfg = structuredClone(cfg)
initialCfg = $state.snapshot(cfg)
onClose()
}
} catch (e) {
hotkeyWarnings = [String(e)]
} finally { saving = false }
}