feat #14740: settings, keyring, tray and manual recording
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte'
|
||||
import {
|
||||
discardCurrentRecording,
|
||||
errorText,
|
||||
getRecordingState,
|
||||
meterFill,
|
||||
onLevels,
|
||||
onRecordingState,
|
||||
stopRecording,
|
||||
type Levels,
|
||||
type RecordingState,
|
||||
type Track,
|
||||
} from '../lib/api'
|
||||
|
||||
let recording = $state<RecordingState>({ state: 'idle' })
|
||||
let levels = $state<Levels>({ mic: 0, out: 0, failed_tracks: [] })
|
||||
let now = $state(Date.now())
|
||||
let busy = $state(false)
|
||||
let error = $state('')
|
||||
|
||||
const tracks: { track: Track; label: string; failed: string }[] = [
|
||||
{ track: 'mic', label: 'Mikrofon (ich)', failed: '⚠ Mikrofonspur ausgefallen' },
|
||||
{ track: 'out', label: 'Lautsprecher (Gegenseite)', failed: '⚠ Lautsprecherspur ausgefallen' },
|
||||
]
|
||||
|
||||
let elapsed = $derived(
|
||||
recording.state === 'recording'
|
||||
? formatElapsed(now - new Date(recording.started_at).getTime())
|
||||
: '00:00',
|
||||
)
|
||||
|
||||
function formatElapsed(ms: number): string {
|
||||
const total = Math.max(0, Math.floor(ms / 1000))
|
||||
const mm = String(Math.floor(total / 60)).padStart(2, '0')
|
||||
const ss = String(total % 60).padStart(2, '0')
|
||||
return `${mm}:${ss}`
|
||||
}
|
||||
|
||||
function setRecording(state: RecordingState) {
|
||||
recording = state
|
||||
if (state.state === 'recording') {
|
||||
levels = { mic: 0, out: 0, failed_tracks: [] }
|
||||
error = ''
|
||||
busy = false
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const unlisten = [onRecordingState(setRecording), onLevels((l) => (levels = l))]
|
||||
getRecordingState().then(setRecording)
|
||||
const timer = setInterval(() => (now = Date.now()), 1000)
|
||||
return () => {
|
||||
clearInterval(timer)
|
||||
unlisten.forEach((p) => p.then((off) => off()))
|
||||
}
|
||||
})
|
||||
|
||||
async function run(action: () => Promise<void>) {
|
||||
busy = true
|
||||
error = ''
|
||||
try {
|
||||
await action()
|
||||
} catch (err) {
|
||||
error = errorText(err)
|
||||
} finally {
|
||||
busy = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<main class="recorder">
|
||||
<div class="status">
|
||||
<span class="pill rec">● Aufnahme läuft</span>
|
||||
<span class="muted">
|
||||
{recording.state === 'recording' ? recording.app : ''} · {elapsed}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{#each tracks as { track, label, failed } (track)}
|
||||
<div class="track">
|
||||
<div class="label">{label}</div>
|
||||
<div class="meter"><div style:width="{meterFill(levels[track]) * 100}%"></div></div>
|
||||
{#if levels.failed_tracks.includes(track)}
|
||||
<div class="failed">{failed}</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn" disabled={busy} onclick={() => run(stopRecording)}>■ Stopp</button>
|
||||
<button class="btn danger" disabled={busy} onclick={() => run(discardCurrentRecording)}>
|
||||
Verwerfen
|
||||
</button>
|
||||
</div>
|
||||
{#if error}
|
||||
<div class="error">{error}</div>
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
<style>
|
||||
:global(body:has(.recorder)) {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.recorder {
|
||||
min-height: 100vh;
|
||||
background: var(--surface);
|
||||
padding: 8px 12px;
|
||||
font-size: 13px;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.status .muted {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.track {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
|
||||
.failed {
|
||||
font-size: 11px;
|
||||
color: var(--rec);
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 9px;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,336 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte'
|
||||
import {
|
||||
errorText,
|
||||
getSettings,
|
||||
hasApiKey,
|
||||
listDevices,
|
||||
meterFill,
|
||||
saveSettings,
|
||||
setApiKey,
|
||||
testDevices,
|
||||
type DeviceInfo,
|
||||
type DeviceLevels,
|
||||
type Devices,
|
||||
type Service,
|
||||
type Settings,
|
||||
} from '../lib/api'
|
||||
|
||||
const services: { id: Service; name: string }[] = [
|
||||
{ id: 'deepscript', name: 'DeepScript' },
|
||||
{ id: 'anthropic', name: 'Anthropic (Claude)' },
|
||||
]
|
||||
|
||||
let settings = $state<Settings | null>(null)
|
||||
let devices = $state<Devices>({ inputs: [], outputs: [] })
|
||||
let keySaved = $state<Record<Service, boolean>>({ deepscript: false, anthropic: false })
|
||||
let keyInput = $state<Record<Service, string>>({ deepscript: '', anthropic: '' })
|
||||
let newApp = $state('')
|
||||
let testing = $state(false)
|
||||
let testResult = $state<DeviceLevels | null>(null)
|
||||
let message = $state('')
|
||||
let error = $state('')
|
||||
|
||||
onMount(load)
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
settings = await getSettings()
|
||||
for (const { id } of services) keySaved[id] = await hasApiKey(id)
|
||||
devices = await listDevices()
|
||||
} catch (err) {
|
||||
error = errorText(err)
|
||||
}
|
||||
}
|
||||
|
||||
/** The device list plus the saved device if it is currently unavailable. */
|
||||
function withSaved(list: DeviceInfo[], saved: string | null): DeviceInfo[] {
|
||||
if (saved === null || list.some((d) => d.id === saved)) return list
|
||||
return [...list, { id: saved, name: `${saved} (nicht verfügbar)` }]
|
||||
}
|
||||
|
||||
async function run(action: () => Promise<void>, done = '') {
|
||||
message = ''
|
||||
error = ''
|
||||
try {
|
||||
await action()
|
||||
message = done
|
||||
} catch (err) {
|
||||
error = errorText(err)
|
||||
}
|
||||
}
|
||||
|
||||
function storeKey(service: Service, key: string) {
|
||||
return run(async () => {
|
||||
await setApiKey(service, key)
|
||||
keySaved[service] = await hasApiKey(service)
|
||||
keyInput[service] = ''
|
||||
}, key ? 'Schlüssel gespeichert' : 'Schlüssel entfernt')
|
||||
}
|
||||
|
||||
function addApp() {
|
||||
const name = newApp.trim().toLowerCase()
|
||||
if (settings && name && !settings.allowlist.includes(name)) {
|
||||
settings.allowlist = [...settings.allowlist, name]
|
||||
}
|
||||
newApp = ''
|
||||
}
|
||||
|
||||
function removeApp(name: string) {
|
||||
if (settings) settings.allowlist = settings.allowlist.filter((a) => a !== name)
|
||||
}
|
||||
|
||||
async function persist() {
|
||||
if (!settings) return
|
||||
if (!Number.isInteger(settings.retention_days) || settings.retention_days < 1) {
|
||||
throw 'Aufbewahrung: bitte eine ganze Zahl ab 1 eingeben'
|
||||
}
|
||||
await saveSettings($state.snapshot(settings))
|
||||
}
|
||||
|
||||
async function runTest() {
|
||||
testing = true
|
||||
testResult = null
|
||||
await run(async () => {
|
||||
await persist()
|
||||
testResult = await testDevices()
|
||||
})
|
||||
testing = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<main class="page">
|
||||
<header class="page-header">
|
||||
<h1>Einstellungen</h1>
|
||||
<a class="btn" href="#/">← Zurück</a>
|
||||
</header>
|
||||
|
||||
{#if settings}
|
||||
<section class="card">
|
||||
<h2>API-Schlüssel</h2>
|
||||
{#each services as { id, name } (id)}
|
||||
<div class="key-row">
|
||||
<span class="key-name">{name}</span>
|
||||
{#if keySaved[id]}
|
||||
<span class="pill ok">gespeichert ✓</span>
|
||||
{:else}
|
||||
<span class="pill missing">fehlt</span>
|
||||
{/if}
|
||||
<input
|
||||
type="password"
|
||||
placeholder={keySaved[id] ? 'Neuen Schlüssel eingeben' : 'Schlüssel eingeben'}
|
||||
autocomplete="off"
|
||||
bind:value={keyInput[id]}
|
||||
/>
|
||||
<button
|
||||
class="btn small"
|
||||
disabled={!keyInput[id].trim()}
|
||||
onclick={() => storeKey(id, keyInput[id])}>Speichern</button
|
||||
>
|
||||
{#if keySaved[id]}
|
||||
<button class="btn small danger" onclick={() => storeKey(id, '')}>Entfernen</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Audio</h2>
|
||||
<div class="grid">
|
||||
<label for="mic">Mikrofon</label>
|
||||
<select id="mic" bind:value={settings.mic_device}>
|
||||
<option value={null}>Standardgerät</option>
|
||||
{#each withSaved(devices.inputs, settings.mic_device) as d (d.id)}
|
||||
<option value={d.id}>{d.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<label for="out">Lautsprecher</label>
|
||||
<select id="out" bind:value={settings.output_device}>
|
||||
<option value={null}>Standardgerät</option>
|
||||
{#each withSaved(devices.outputs, settings.output_device) as d (d.id)}
|
||||
<option value={d.id}>{d.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<p class="hint">
|
||||
Bitte mit Headset telefonieren – sonst landet die Gegenseite auch auf der Mikrofonspur.
|
||||
</p>
|
||||
<div class="test">
|
||||
<button class="btn" disabled={testing} onclick={runTest}>
|
||||
{testing ? 'Test läuft …' : 'Test'}
|
||||
</button>
|
||||
<span class="muted">
|
||||
{testing
|
||||
? 'Bitte 5 Sekunden sprechen und etwas abspielen.'
|
||||
: 'Nimmt 5 Sekunden auf und zeigt den Pegel beider Spuren.'}
|
||||
</span>
|
||||
</div>
|
||||
{#if testResult}
|
||||
<div class="levels">
|
||||
<span>Mikrofon</span>
|
||||
<div class="meter"><div style:width="{meterFill(testResult.mic) * 100}%"></div></div>
|
||||
<span>Lautsprecher</span>
|
||||
<div class="meter"><div style:width="{meterFill(testResult.out) * 100}%"></div></div>
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Gesprächserkennung</h2>
|
||||
<p class="muted">Programme, deren Mikrofonnutzung als Gespräch zählt:</p>
|
||||
<ul class="allowlist">
|
||||
{#each settings.allowlist as name (name)}
|
||||
<li>
|
||||
<span>{name}</span>
|
||||
<button class="remove" title="Entfernen" onclick={() => removeApp(name)}>✕</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
<form
|
||||
class="add"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
addApp()
|
||||
}}
|
||||
>
|
||||
<input placeholder="z. B. zoom.exe" bind:value={newApp} />
|
||||
<button class="btn small" type="submit" disabled={!newApp.trim()}>Hinzufügen</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>Allgemein</h2>
|
||||
<div class="grid">
|
||||
<label for="language">Sprache der Gespräche</label>
|
||||
<select id="language" bind:value={settings.language}>
|
||||
<option value="de">Deutsch</option>
|
||||
<option value="en">Englisch</option>
|
||||
</select>
|
||||
<label for="retention">Aufbewahrung der Audiodateien</label>
|
||||
<span><input id="retention" type="number" min="1" bind:value={settings.retention_days} /> Tage</span>
|
||||
<label for="autostart">Beim Anmelden starten</label>
|
||||
<input id="autostart" type="checkbox" bind:checked={settings.autostart} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="footer">
|
||||
<button class="btn primary" onclick={() => run(persist, 'Einstellungen gespeichert ✓')}>
|
||||
Speichern
|
||||
</button>
|
||||
{#if message}<span class="saved">{message}</span>{/if}
|
||||
{#if error}<span class="error">{error}</span>{/if}
|
||||
</div>
|
||||
{:else if error}
|
||||
<p class="error">{error}</p>
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.key-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.key-name {
|
||||
width: 150px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.key-row input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: 220px 1fr;
|
||||
align-items: center;
|
||||
gap: 8px 12px;
|
||||
}
|
||||
|
||||
.grid select {
|
||||
max-width: 380px;
|
||||
}
|
||||
|
||||
.grid input[type='number'] {
|
||||
width: 70px;
|
||||
}
|
||||
|
||||
.grid input[type='checkbox'] {
|
||||
justify-self: start;
|
||||
}
|
||||
|
||||
.hint {
|
||||
margin: 12px 0;
|
||||
padding: 8px 10px;
|
||||
border-radius: 6px;
|
||||
background: #fff4d6;
|
||||
color: #8a6100;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.test {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.levels {
|
||||
display: grid;
|
||||
grid-template-columns: 100px 1fr;
|
||||
align-items: center;
|
||||
gap: 6px 10px;
|
||||
margin-top: 10px;
|
||||
max-width: 420px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.allowlist {
|
||||
list-style: none;
|
||||
margin: 8px 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.allowlist li {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 2px 4px 2px 10px;
|
||||
border-radius: 999px;
|
||||
background: var(--primary-soft);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.remove {
|
||||
border: none;
|
||||
background: none;
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.remove:hover {
|
||||
color: var(--rec);
|
||||
}
|
||||
|
||||
.add {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.saved {
|
||||
color: var(--ok);
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user