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
+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`
}