config and ffmpeg bootstrap

This commit is contained in:
2026-05-11 23:48:23 +03:00
parent 472aa6f9ec
commit c64ec2045e
15 changed files with 8710 additions and 68 deletions
+34 -56
View File
@@ -1,61 +1,39 @@
<script lang="ts">
let recording = $state(false)
import { onMount } from "svelte"
import { api, type AppStatus } from "./lib/api"
import Loading from "./lib/Loading.svelte"
import Bootstrap from "./lib/Bootstrap.svelte"
import FirstRun from "./lib/FirstRun.svelte"
import Main from "./lib/Main.svelte"
function toggle() {
recording = !recording
type View = "loading" | "bootstrap" | "first-run" | "main"
let view: View = $state("loading")
async function refresh() {
view = "loading"
let status: AppStatus
try {
status = await api.getStatus()
} catch (e) {
console.error("get_status failed", e)
view = "bootstrap"
return
}
if (status.ffmpeg === "missing") view = "bootstrap"
else if (status.needs_first_run) view = "first-run"
else view = "main"
}
onMount(refresh)
</script>
<main>
<header>
<h1>ByteSize</h1>
<p>screen-to-clip recorder</p>
</header>
<section class="controls">
<button onclick={toggle} class:active={recording}>
{recording ? "stop" : "start"}
</button>
</section>
</main>
<style>
main {
padding: 1.5rem;
max-width: 480px;
margin: 0 auto;
}
header h1 {
margin: 0 0 0.25rem;
font-size: 1.5rem;
letter-spacing: -0.01em;
}
header p {
margin: 0 0 1.5rem;
color: #888;
font-size: 0.875rem;
}
.controls {
display: flex;
gap: 0.5rem;
}
button {
font: inherit;
padding: 0.5rem 1rem;
border: 1px solid currentColor;
background: transparent;
color: inherit;
cursor: pointer;
border-radius: 4px;
}
button.active {
background: #c33;
border-color: #c33;
color: white;
}
</style>
{#if view === "loading"}
<Loading />
{:else if view === "bootstrap"}
<Bootstrap onReady={refresh} />
{:else if view === "first-run"}
<FirstRun onDone={refresh} />
{:else}
<Main />
{/if}
+141
View File
@@ -0,0 +1,141 @@
<script lang="ts">
import { api, formatBytes, type DownloadProgress } from "./api"
let { onReady }: { onReady: () => void } = $props()
type Phase = "idle" | "downloading" | "error"
let phase: Phase = $state("idle")
let progress: DownloadProgress | null = $state(null)
let errMsg: string | null = $state(null)
async function start() {
phase = "downloading"
errMsg = null
progress = null
const unlisten = await api.onFfmpegProgress((p) => {
progress = p
})
try {
await api.downloadFfmpeg()
unlisten()
onReady()
} catch (e) {
unlisten()
errMsg = String(e)
phase = "error"
}
}
</script>
<main>
<header>
<h1>ByteSize</h1>
<p class="sub">set up encoder</p>
</header>
{#if phase === "idle"}
<p>
ByteSize needs ffmpeg to encode video. The download is around 30 MB and
is verified against a published SHA-256 checksum.
</p>
<div class="row">
<button class="primary" onclick={start}>download ffmpeg</button>
</div>
<p class="hint">
Already have ffmpeg? Drop <code>ffmpeg.exe</code> into the
<code>bin/</code> folder next to the app, then click below.
</p>
<div class="row">
<button onclick={onReady}>i added it manually</button>
</div>
{:else if phase === "downloading"}
<p>downloading ffmpeg...</p>
<progress
value={progress?.downloaded ?? 0}
max={progress?.total ?? undefined}
></progress>
<p class="hint">
{#if progress && progress.total}
{formatBytes(progress.downloaded)} / {formatBytes(progress.total)}
{:else if progress}
{formatBytes(progress.downloaded)} downloaded
{/if}
</p>
{:else}
<p class="err">download failed</p>
<pre>{errMsg}</pre>
<div class="row">
<button onclick={start}>retry</button>
<button onclick={onReady}>i added it manually</button>
</div>
{/if}
</main>
<style>
main {
padding: 2rem;
max-width: 560px;
margin: 0 auto;
}
header h1 {
margin: 0 0 0.25rem;
font-size: 1.5rem;
letter-spacing: -0.01em;
}
.sub {
color: #888;
font-size: 0.875rem;
margin: 0 0 1.5rem;
}
.row {
display: flex;
gap: 0.5rem;
margin: 1rem 0;
}
.hint {
color: #888;
font-size: 0.85rem;
}
code {
background: #2a2a2a;
padding: 0.1rem 0.35rem;
border-radius: 3px;
font-size: 0.85em;
}
progress {
width: 100%;
height: 8px;
}
pre {
background: #2a2a2a;
padding: 0.75rem;
border-radius: 4px;
overflow-x: auto;
font-size: 0.8rem;
color: #ec9a9a;
}
.err {
color: #ec9a9a;
}
button {
font: inherit;
padding: 0.5rem 1rem;
border: 1px solid #444;
background: transparent;
color: inherit;
cursor: pointer;
border-radius: 4px;
}
button:hover {
border-color: #888;
}
button.primary {
background: #4a8;
border-color: #4a8;
color: #111;
}
button.primary:hover {
background: #5b9;
border-color: #5b9;
}
</style>
+137
View File
@@ -0,0 +1,137 @@
<script lang="ts">
import { api } from "./api"
let { onDone }: { onDone: () => void } = $props()
let start = $state("")
let stop = $state("")
let pause = $state("")
let saving = $state(false)
async function save() {
saving = true
try {
const cfg = await api.getConfig()
cfg.hotkeys.start = start.trim() || null
cfg.hotkeys.stop = stop.trim() || null
cfg.hotkeys.pause = pause.trim() || null
await api.saveConfig(cfg)
onDone()
} finally {
saving = false
}
}
let valid = $derived(start.trim() && stop.trim() && pause.trim())
</script>
<main>
<header>
<h1>ByteSize</h1>
<p class="sub">assign your hotkeys</p>
</header>
<p>
ByteSize doesn't ship default hotkeys. Pick combinations that won't clash
with apps you use. You can change these later in settings.
</p>
<div class="form">
<label>
<span>start</span>
<input bind:value={start} placeholder="e.g. F9" />
</label>
<label>
<span>stop</span>
<input bind:value={stop} placeholder="e.g. F9" />
</label>
<label>
<span>pause</span>
<input bind:value={pause} placeholder="e.g. F10" />
</label>
</div>
<div class="row">
<button class="primary" disabled={!valid || saving} onclick={save}>
{saving ? "saving..." : "save and continue"}
</button>
</div>
<p class="hint">
Live key capture isn't wired up yet - for now type the combination as text
(F9, Ctrl+Shift+R, etc).
</p>
</main>
<style>
main {
padding: 2rem;
max-width: 560px;
margin: 0 auto;
}
header h1 {
margin: 0 0 0.25rem;
font-size: 1.5rem;
letter-spacing: -0.01em;
}
.sub {
color: #888;
font-size: 0.875rem;
margin: 0 0 1.5rem;
}
.form {
display: grid;
gap: 0.75rem;
margin: 1.25rem 0;
}
label {
display: grid;
grid-template-columns: 80px 1fr;
align-items: center;
gap: 0.75rem;
}
label span {
color: #aaa;
font-size: 0.875rem;
}
input {
font: inherit;
padding: 0.45rem 0.6rem;
border: 1px solid #444;
background: #222;
color: inherit;
border-radius: 4px;
}
input:focus {
outline: none;
border-color: #4a8;
}
.row {
display: flex;
gap: 0.5rem;
margin: 1rem 0;
}
.hint {
color: #888;
font-size: 0.85rem;
}
button {
font: inherit;
padding: 0.5rem 1rem;
border: 1px solid #444;
background: transparent;
color: inherit;
cursor: pointer;
border-radius: 4px;
}
button:hover:not(:disabled) {
border-color: #888;
}
button.primary {
background: #4a8;
border-color: #4a8;
color: #111;
}
button.primary:disabled {
background: #333;
border-color: #333;
color: #666;
cursor: not-allowed;
}
</style>
+14
View File
@@ -0,0 +1,14 @@
<main class="center">
<p class="muted">loading...</p>
</main>
<style>
main.center {
min-height: 100vh;
display: grid;
place-items: center;
}
.muted {
color: #777;
}
</style>
+125
View File
@@ -0,0 +1,125 @@
<script lang="ts">
import { api, type Config } from "./api"
import { onMount } from "svelte"
let recording: boolean = $state(false)
let config: Config | null = $state(null)
onMount(async () => {
config = await api.getConfig()
})
function toggle() {
recording = !recording
}
</script>
<main>
<header>
<h1>ByteSize</h1>
<p class="sub">ready</p>
</header>
<section class="controls">
<button onclick={toggle} class:active={recording}>
{recording ? "stop" : "start"}
</button>
</section>
{#if config}
<section class="cfg">
<h2>current settings</h2>
<dl>
<dt>format</dt>
<dd>{config.export.default_format}</dd>
<dt>fps</dt>
<dd>{config.capture.default_fps}</dd>
<dt>cursor</dt>
<dd>{config.capture.capture_cursor ? "on" : "off"}</dd>
<dt>audio</dt>
<dd>{config.capture.capture_audio ? "on" : "off"}</dd>
<dt>hotkeys</dt>
<dd>
start: {config.hotkeys.start ?? "-"} |
stop: {config.hotkeys.stop ?? "-"} |
pause: {config.hotkeys.pause ?? "-"}
</dd>
</dl>
</section>
{/if}
<p class="hint">
capture and encode aren't wired up yet. that's next.
</p>
</main>
<style>
main {
padding: 2rem;
max-width: 720px;
margin: 0 auto;
}
header h1 {
margin: 0 0 0.25rem;
font-size: 1.5rem;
letter-spacing: -0.01em;
}
.sub {
color: #888;
font-size: 0.875rem;
margin: 0 0 1.5rem;
}
.controls {
margin: 1rem 0 2rem;
}
button {
font: inherit;
padding: 0.6rem 1.2rem;
border: 1px solid #444;
background: transparent;
color: inherit;
cursor: pointer;
border-radius: 4px;
font-size: 1rem;
}
button:hover {
border-color: #888;
}
button.active {
background: #c33;
border-color: #c33;
color: #fff;
}
.cfg {
border: 1px solid #2a2a2a;
border-radius: 6px;
padding: 1rem 1.25rem;
background: #1e1e1e;
}
.cfg h2 {
margin: 0 0 0.75rem;
font-size: 0.85rem;
color: #888;
font-weight: normal;
text-transform: uppercase;
letter-spacing: 0.05em;
}
dl {
display: grid;
grid-template-columns: 100px 1fr;
gap: 0.5rem 1rem;
margin: 0;
font-size: 0.9rem;
}
dt {
color: #888;
}
dd {
margin: 0;
}
.hint {
color: #888;
font-size: 0.85rem;
margin-top: 2rem;
}
</style>
+66
View File
@@ -0,0 +1,66 @@
import { invoke } from "@tauri-apps/api/core"
import { listen, type UnlistenFn } from "@tauri-apps/api/event"
export type FfmpegStatus = "ready" | "missing"
export type AppStatus = {
ffmpeg: FfmpegStatus
needs_first_run: boolean
}
export type Format = "gif" | "webm" | "mp4"
export type GifDither = "floyd_steinberg" | "bayer" | "none"
export type WebmCodec = "vp9" | "av1"
export type Mp4Codec = "h264" | "h265"
export type ExportConfig = {
default_format: Format
gif_dither: GifDither
webm_codec: WebmCodec
mp4_codec: Mp4Codec
}
export type CaptureConfig = {
default_fps: number
capture_cursor: boolean
capture_audio: boolean
}
export type HotkeyConfig = {
start: string | null
stop: string | null
pause: string | null
}
export type UpdatesConfig = {
check_on_launch: boolean
}
export type Config = {
export: ExportConfig
capture: CaptureConfig
hotkeys: HotkeyConfig
updates: UpdatesConfig
output_dir: string | null
}
export type DownloadProgress = {
downloaded: number
total: number | null
}
export const api = {
getStatus: () => invoke<AppStatus>("get_status"),
getConfig: () => invoke<Config>("get_config"),
saveConfig: (config: Config) => invoke<void>("save_config", { config }),
downloadFfmpeg: () => invoke<void>("download_ffmpeg"),
onFfmpegProgress: (handler: (p: DownloadProgress) => void): Promise<UnlistenFn> =>
listen<DownloadProgress>("ffmpeg-progress", (e) => handler(e.payload)),
}
export function formatBytes(n: number): string {
if (n < 1024) return `${n} B`
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
if (n < 1024 * 1024 * 1024) return `${(n / 1024 / 1024).toFixed(1)} MB`
return `${(n / 1024 / 1024 / 1024).toFixed(2)} GB`
}