244 lines
14 KiB
Svelte
244 lines
14 KiB
Svelte
<script lang="ts">
|
|
import { onMount } from "svelte"
|
|
import { IconActivity, IconAdjustmentsHorizontal, IconFileExport, IconFolder, IconKeyboard, IconScan } from "./ui/icons"
|
|
import WindowBar from "./ui/WindowBar.svelte"
|
|
import WorkspaceScroll from "./ui/WorkspaceScroll.svelte"
|
|
import Dropdown from "./ui/Dropdown.svelte"
|
|
import Toggle from "./ui/Toggle.svelte"
|
|
import { appear, disclosure } from "./ui/motion"
|
|
import { scrollbar } from "./ui/scrollbar"
|
|
import { api, type Config, type CodecAvailability, type DiagnosticsInfo } from "./api"
|
|
import HotkeyInput from "./HotkeyInput.svelte"
|
|
import { open } from "@tauri-apps/plugin-dialog"
|
|
|
|
let { onClose, onCheckUpdates }: { onClose: () => void; onCheckUpdates: () => void } = $props()
|
|
|
|
let cfg: Config | null = $state(null)
|
|
let saving: boolean = $state(false)
|
|
let hotkeyWarnings: string[] = $state([])
|
|
let activeTab: string = $state("capture")
|
|
let initialCfg: Config | null = $state(null)
|
|
let codecs: CodecAvailability | null = $state(null)
|
|
|
|
let dirty = $derived.by(() => {
|
|
if (!cfg || !initialCfg) return false
|
|
return cfg.theme !== initialCfg.theme
|
|
|| cfg.capture.default_fps !== initialCfg.capture.default_fps
|
|
|| cfg.capture.capture_cursor !== initialCfg.capture.capture_cursor
|
|
|| cfg.capture.capture_audio !== initialCfg.capture.capture_audio
|
|
|| cfg.capture.capture_quality !== initialCfg.capture.capture_quality
|
|
|| cfg.capture.limit_capture_fps !== initialCfg.capture.limit_capture_fps
|
|
|| cfg.export.default_format !== initialCfg.export.default_format
|
|
|| cfg.export.gif_dither !== initialCfg.export.gif_dither
|
|
|| cfg.export.webm_codec !== initialCfg.export.webm_codec
|
|
|| cfg.export.mp4_codec !== initialCfg.export.mp4_codec
|
|
|| cfg.hotkeys.start !== initialCfg.hotkeys.start
|
|
|| cfg.hotkeys.stop !== initialCfg.hotkeys.stop
|
|
|| cfg.hotkeys.pause !== initialCfg.hotkeys.pause
|
|
|| cfg.updates.check_on_launch !== initialCfg.updates.check_on_launch
|
|
|| cfg.output_dir !== initialCfg.output_dir
|
|
})
|
|
|
|
let diagnostics: DiagnosticsInfo | null = $state(null)
|
|
|
|
const TABS = [
|
|
{ id: "capture", label: "Capture", icon: IconScan },
|
|
{ id: "export", label: "Export", icon: IconFileExport },
|
|
{ id: "hotkeys", label: "Shortcuts", icon: IconKeyboard },
|
|
{ id: "output", label: "Files", icon: IconFolder },
|
|
{ id: "system", label: "System", icon: IconAdjustmentsHorizontal },
|
|
{ id: "diagnostics", label: "Diagnostics", icon: IconActivity },
|
|
]
|
|
const descriptions: Record<string, string> = {
|
|
capture: "Choose defaults for new recordings.",
|
|
export: "Set format and encoding defaults for new clips.",
|
|
hotkeys: "Control recording while ByteSize is in the background.",
|
|
output: "Set where new exports are saved.",
|
|
system: "Manage appearance and app updates.",
|
|
diagnostics: "Check encoder availability and review recent activity.",
|
|
}
|
|
const rates = [1,2,5,10,15,24,30,60].map(value => ({value,label:value+" FPS"}))
|
|
const qualities = [{value:"auto",label:"Auto"},{value:"full",label:"Full"}] as const
|
|
const formats = [{value:"mp4",label:"MP4"},{value:"webm",label:"WebM"},{value:"gif",label:"GIF"}] as const
|
|
const dithers = [{value:"floyd_steinberg",label:"Floyd-Steinberg"},{value:"bayer",label:"Bayer"},{value:"none",label:"None"}] as const
|
|
const themes = [{value:"dark",label:"Dark"},{value:"light",label:"Light"}] as const
|
|
let mp4 = $derived.by(() => [
|
|
{value:"h264",label:codecs?.h264 === false ? "H.264 unavailable" : "H.264",disabled:codecs?.h264 === false},
|
|
{value:"h265",label:codecs?.h265 === false ? "H.265 unavailable" : "H.265",disabled:codecs?.h265 === false},
|
|
] as const)
|
|
let webm = $derived.by(() => [
|
|
{value:"vp9",label:codecs?.vp9 === false ? "VP9 unavailable" : "VP9",disabled:codecs?.vp9 === false},
|
|
{value:"av1",label:codecs?.av1 === false ? "AV1 unavailable" : "AV1",disabled:codecs?.av1 === false},
|
|
] as const)
|
|
|
|
onMount(async () => {
|
|
cfg = await api.getConfig()
|
|
initialCfg = $state.snapshot(cfg)
|
|
try { codecs = await api.codecAvailability() } catch { codecs = null }
|
|
})
|
|
|
|
$effect(() => {
|
|
if (cfg) document.documentElement.setAttribute("data-theme", cfg.theme)
|
|
})
|
|
|
|
$effect(() => {
|
|
if (activeTab !== "diagnostics") return
|
|
api.diagnosticsInfo().then(d => { diagnostics = d }).catch(() => { diagnostics = null })
|
|
})
|
|
|
|
async function refreshDiagnostics() {
|
|
try { diagnostics = await api.diagnosticsInfo() } catch { diagnostics = null }
|
|
}
|
|
|
|
function openLogFolder() {
|
|
void api.openLogDir().catch(e => console.warn("could not open the log folder:", e))
|
|
}
|
|
|
|
async function save() {
|
|
if (!cfg) return
|
|
|
|
// Check for duplicate hotkeys
|
|
const keys = [cfg.hotkeys.start, cfg.hotkeys.stop, cfg.hotkeys.pause].filter(Boolean)
|
|
const unique = new Set(keys)
|
|
if (keys.length !== unique.size) {
|
|
hotkeyWarnings = ['Multiple actions assigned to the same key - each hotkey must be unique']
|
|
return
|
|
}
|
|
|
|
saving = true
|
|
hotkeyWarnings = []
|
|
try {
|
|
const result = await api.saveConfig(cfg)
|
|
const failed: string[] = []
|
|
if (result.hotkey_result.start_ok === false) failed.push("start")
|
|
if (result.hotkey_result.stop_ok === false) failed.push("stop")
|
|
if (result.hotkey_result.pause_ok === false) failed.push("pause")
|
|
if (failed.length > 0) {
|
|
hotkeyWarnings = [`Could not register the ${failed.join(", ")} shortcuts. Your settings were kept.`]
|
|
} else {
|
|
initialCfg = $state.snapshot(cfg)
|
|
onClose()
|
|
}
|
|
} catch (e) {
|
|
hotkeyWarnings = [String(e)]
|
|
} finally { saving = false }
|
|
}
|
|
|
|
function cancel() {
|
|
if (saving) return
|
|
if (initialCfg) document.documentElement.setAttribute("data-theme", initialCfg.theme)
|
|
onClose()
|
|
}
|
|
|
|
async function pickOutputDir() {
|
|
if (!cfg) return
|
|
try {
|
|
const picked = await open({ directory: true, defaultPath: cfg.output_dir ?? undefined })
|
|
if (typeof picked === "string") cfg.output_dir = picked
|
|
} catch (e) {
|
|
console.warn("directory picker failed:", e)
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<WindowBar current="settings" onCapture={cancel} onSettings={cancel} disabled={saving} />
|
|
<WorkspaceScroll>
|
|
{#if cfg}
|
|
<section class="settings-workspace">
|
|
<nav class="settings-nav" aria-label="Settings sections">
|
|
<h3>Settings</h3>
|
|
{#each TABS as tab}
|
|
<button type="button" class="button ghost" aria-current={activeTab === tab.id ? "true" : undefined}
|
|
onclick={() => activeTab = tab.id}><tab.icon size={17} />{tab.label}</button>
|
|
{/each}
|
|
</nav>
|
|
{#key activeTab}
|
|
<div class="settings-pane" use:appear>
|
|
<header>
|
|
<h1>{TABS.find(tab => tab.id === activeTab)?.label}</h1>
|
|
<p class="note">{descriptions[activeTab]}</p>
|
|
</header>
|
|
<div class="settings-fields">
|
|
{#if activeTab === "capture"}
|
|
<div class="setting-row"><div><strong>Export frame rate</strong><p class="note">Preselected when you finish a recording.</p></div><Dropdown label="Default export frame rate" options={rates} bind:value={cfg.capture.default_fps} disabled={saving} /></div>
|
|
<div class="setting-row"><div><strong>Limit capture frame rate</strong><p class="note">Record at the selected rate instead of the display rate.</p></div><Toggle label="Limit capture frame rate" bind:checked={cfg.capture.limit_capture_fps} disabled={saving} /></div>
|
|
<div class="setting-row"><div><strong>Resolution</strong><p class="note">Auto caps the longest side at 1920 px.</p></div><Dropdown label="Default capture resolution" options={qualities} bind:value={cfg.capture.capture_quality} disabled={saving} /></div>
|
|
<div class="setting-row"><strong>Record mouse pointer</strong><Toggle label="Record mouse pointer" bind:checked={cfg.capture.capture_cursor} disabled={saving} /></div>
|
|
<div class="setting-row"><strong>Record system audio</strong><Toggle label="Record system audio" bind:checked={cfg.capture.capture_audio} disabled={saving} /></div>
|
|
{:else if activeTab === "export"}
|
|
<div class="setting-row"><div><strong>Default format</strong><p class="note">Preselected when you finish a recording.</p></div><Dropdown label="Default format" options={formats} bind:value={cfg.export.default_format} disabled={saving} /></div>
|
|
<details class="advanced" use:disclosure><summary>Advanced encoding</summary>
|
|
<div class="disclosure-body">
|
|
<div class="setting-row"><strong>GIF dithering</strong><Dropdown label="Default GIF dithering" options={dithers} bind:value={cfg.export.gif_dither} disabled={saving} /></div>
|
|
<div class="setting-row"><strong>MP4 codec</strong><Dropdown label="MP4 codec" options={mp4} bind:value={cfg.export.mp4_codec} disabled={saving} /></div>
|
|
<div class="setting-row"><strong>WebM codec</strong><Dropdown label="WebM codec" options={webm} bind:value={cfg.export.webm_codec} disabled={saving} /></div>
|
|
</div>
|
|
</details>
|
|
{:else if activeTab === "hotkeys"}
|
|
<div class="setting-row"><strong>Start recording</strong><HotkeyInput label="Start recording" bind:value={cfg.hotkeys.start} placeholder="Assign" /></div>
|
|
<div class="setting-row"><strong>Stop recording</strong><HotkeyInput label="Stop recording" bind:value={cfg.hotkeys.stop} placeholder="Assign" /></div>
|
|
<div class="setting-row"><strong>Pause / resume</strong><HotkeyInput label="Pause or resume" bind:value={cfg.hotkeys.pause} placeholder="Assign" /></div>
|
|
{:else if activeTab === "output"}
|
|
<div class="setting-row"><label for="default-output"><strong>Default output folder</strong></label>
|
|
<input id="default-output" class="field mono folder" placeholder="Default output folder" value={cfg.output_dir ?? ""} oninput={e => { cfg!.output_dir = e.currentTarget.value.trim() || null }} disabled={saving} />
|
|
</div>
|
|
<div class="setting-row"><strong>Choose location</strong><button type="button" class="button" onclick={pickOutputDir} disabled={saving}><IconFolder size={17} />Browse</button></div>
|
|
{:else if activeTab === "system"}
|
|
<div class="setting-row"><strong>Appearance</strong><Dropdown label="Appearance" options={themes} bind:value={cfg.theme} disabled={saving} /></div>
|
|
<div class="setting-row"><strong>Check for updates on launch</strong><Toggle label="Check for updates on launch" bind:checked={cfg.updates.check_on_launch} disabled={saving} /></div>
|
|
<div class="setting-row"><strong>App updates</strong><button type="button" class="button" onclick={onCheckUpdates} disabled={saving}>Check for updates</button></div>
|
|
{:else}
|
|
<div class="setting-row"><strong>ByteSize</strong><code class="mono selectable">{diagnostics?.app_version ?? "Loading..."}</code></div>
|
|
<div class="setting-row"><strong>Encoder</strong><code class="mono selectable">{diagnostics?.ffmpeg_version ?? "Loading..."}</code></div>
|
|
<div class="setting-row"><div><strong>Log folder</strong><p class="note log-path selectable">{diagnostics?.log_dir ?? ""}</p></div>
|
|
<button type="button" class="button" onclick={openLogFolder} disabled={!diagnostics}><IconFolder size={17} />Show logs</button>
|
|
</div>
|
|
<div class="row between"><h3>Recent activity</h3><button type="button" class="button ghost" onclick={refreshDiagnostics}>Refresh</button></div>
|
|
<div class="log-scroll"><pre class="mono" use:scrollbar={"y"}>{diagnostics?.log_tail || "No recent log entries."}</pre></div>
|
|
{/if}
|
|
</div>
|
|
{#if hotkeyWarnings.length}
|
|
<div class="notice problem warnings" role="alert" use:appear>{#each hotkeyWarnings as warning}<p>{warning}</p>{/each}</div>
|
|
{/if}
|
|
<div class="actions wrap setting-footer">
|
|
{#if activeTab !== "diagnostics"}<button class="button primary" type="button" onclick={save} disabled={saving || !dirty}>{saving ? "Saving..." : "Save changes"}</button>{/if}
|
|
<button class="button ghost" type="button" onclick={cancel} disabled={saving}>{dirty ? "Cancel" : "Close"}</button>
|
|
</div>
|
|
</div>
|
|
{/key}
|
|
</section>
|
|
{/if}
|
|
</WorkspaceScroll>
|
|
|
|
<style>
|
|
.settings-workspace { display:grid; grid-template-columns:minmax(155px,215px) minmax(0,1fr); flex:1; }
|
|
.settings-nav { display:grid; align-content:start; gap:4px; padding:20px; background:var(--caption); }
|
|
.settings-nav h3 { margin:4px 12px 12px; }
|
|
.settings-nav button { justify-content:flex-start; }
|
|
.settings-nav button[aria-current="true"] { color:var(--ink); background:var(--raised); }
|
|
.settings-nav button[aria-current="true"] :global(svg) { color:var(--signal); }
|
|
:global(:root[data-theme="light"]) .settings-nav button[aria-current="true"] :global(svg) { color:#587324; }
|
|
.settings-pane { min-width:0; max-width:840px; padding:clamp(20px,4vw,44px); }
|
|
header { margin-bottom:20px; }
|
|
header .note { margin-top:8px; }
|
|
.settings-fields { border-radius:var(--radius); background:var(--caption); padding:0 16px; }
|
|
.setting-row { display:flex; justify-content:space-between; align-items:center; gap:12px; padding:12px 0; border-bottom:var(--edge) solid var(--rule); }
|
|
.setting-row:last-child { border-bottom:0; }
|
|
.setting-row > .folder { width:52%; }
|
|
.setting-row :global(.combo) { width:min(47%,205px); min-width:104px; flex:0 0 auto; }
|
|
.setting-row .button { white-space:nowrap; flex:0 0 auto; }
|
|
.setting-row p { margin-top:4px; }
|
|
.setting-footer { margin-top:20px; }
|
|
.warnings { margin-top:12px; }
|
|
.advanced summary { padding-block:12px; }
|
|
.log-path { overflow-wrap:anywhere; }
|
|
.log-scroll { position:relative; padding-bottom:12px; }
|
|
pre { margin:0; max-height:230px; overflow:auto; overflow-wrap:anywhere; white-space:pre-wrap; padding:12px 16px 12px 12px; border-radius:var(--control-radius); background:var(--input); color:var(--copy); }
|
|
@media(max-width:680px) {
|
|
.settings-workspace { grid-template-columns:1fr; }
|
|
.settings-nav { display:flex; flex-wrap:wrap; padding:8px 12px; }
|
|
.settings-nav h3 { width:100%; }
|
|
.settings-pane { padding:16px; }
|
|
}
|
|
</style>
|