191 lines
4.5 KiB
Svelte
191 lines
4.5 KiB
Svelte
<script lang="ts">
|
|
import { api } from "./api"
|
|
import HotkeyInput from "./HotkeyInput.svelte"
|
|
|
|
let { onDone }: { onDone: () => void } = $props()
|
|
|
|
let start: string | null = $state(null)
|
|
let stop: string | null = $state(null)
|
|
let pause: string | null = $state(null)
|
|
let saving: boolean = $state(false)
|
|
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 {
|
|
const cfg = await api.getConfig()
|
|
cfg.hotkeys.start = start
|
|
cfg.hotkeys.stop = stop
|
|
cfg.hotkeys.pause = pause
|
|
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) {
|
|
warnings = [`${failed.join(", ")} - hotkey may be in use by another app. try different keys.`]
|
|
} else {
|
|
onDone()
|
|
}
|
|
} catch (e) {
|
|
warnings = [String(e)]
|
|
} finally { saving = false }
|
|
}
|
|
|
|
let valid = $derived(!!start && !!stop && !!pause)
|
|
</script>
|
|
|
|
<div class="stage">
|
|
<div class="card">
|
|
<div class="card-head">
|
|
<div class="logo">BYTESIZE</div>
|
|
<div class="tag">assign your hotkeys</div>
|
|
</div>
|
|
|
|
<div class="body">
|
|
<p class="copy">
|
|
No defaults are shipped. Pick combos that work for you - you can change these later in settings.
|
|
</p>
|
|
|
|
<div class="fields">
|
|
<label class="field">
|
|
<span class="field-label">Start recording</span>
|
|
<HotkeyInput bind:value={start} placeholder="e.g. F9" />
|
|
</label>
|
|
<label class="field">
|
|
<span class="field-label">Stop recording</span>
|
|
<HotkeyInput bind:value={stop} placeholder="e.g. F10" />
|
|
</label>
|
|
<label class="field">
|
|
<span class="field-label">Pause / resume</span>
|
|
<HotkeyInput bind:value={pause} placeholder="e.g. F11" />
|
|
</label>
|
|
</div>
|
|
|
|
{#if warnings.length > 0}
|
|
<div class="warn" role="alert">
|
|
{#each warnings as w}<p>{w}</p>{/each}
|
|
</div>
|
|
{/if}
|
|
|
|
<button class="btn-primary" onclick={save} disabled={!valid || saving}>
|
|
{saving ? "Saving" : "Save and continue"}
|
|
</button>
|
|
|
|
<p class="hint">Click a field, press your combo. Escape to cancel.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.stage {
|
|
min-height: 100vh;
|
|
display: grid;
|
|
place-items: center;
|
|
padding: 24px;
|
|
background: var(--bg);
|
|
}
|
|
|
|
.card {
|
|
width: 100%;
|
|
max-width: 400px;
|
|
background: var(--bg-2);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--r-md);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.card-head {
|
|
padding: 28px 24px 20px;
|
|
border-bottom: 1px solid var(--border);
|
|
text-align: center;
|
|
}
|
|
|
|
.logo {
|
|
font-family: var(--mono);
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
letter-spacing: 0.12em;
|
|
color: var(--accent);
|
|
}
|
|
|
|
.tag {
|
|
margin-top: 6px;
|
|
font-size: 12px;
|
|
color: var(--text-3);
|
|
letter-spacing: 0.02em;
|
|
}
|
|
|
|
.body {
|
|
padding: 24px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 16px;
|
|
}
|
|
|
|
.copy {
|
|
margin: 0;
|
|
font-size: 13px;
|
|
line-height: 1.6;
|
|
color: var(--text-2);
|
|
text-align: center;
|
|
}
|
|
|
|
.fields {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 14px;
|
|
}
|
|
|
|
.field {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 6px;
|
|
}
|
|
|
|
.field-label {
|
|
font-size: 11px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.08em;
|
|
color: var(--text-3);
|
|
}
|
|
|
|
.btn-primary {
|
|
width: 100%;
|
|
padding: 11px 16px;
|
|
background: var(--accent);
|
|
border: none;
|
|
color: var(--accent-text);
|
|
border-radius: var(--r-sm);
|
|
font-family: var(--sans);
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: background 80ms;
|
|
}
|
|
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
|
|
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
|
|
|
|
.hint {
|
|
margin: 0;
|
|
font-size: 11px;
|
|
color: var(--text-3);
|
|
text-align: center;
|
|
}
|
|
|
|
.warn {
|
|
padding: 10px 14px;
|
|
background: var(--err-dim);
|
|
border: 1px solid var(--err-border);
|
|
border-radius: var(--r-sm);
|
|
text-align: center;
|
|
}
|
|
.warn p { margin: 0; font-size: 12px; color: var(--err); }
|
|
</style>
|