142 lines
3.0 KiB
Svelte
142 lines
3.0 KiB
Svelte
<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>
|