feat #14740: automatic call detection on windows
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+2
-3
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte'
|
||||
import Prompt from './routes/Prompt.svelte'
|
||||
import Recorder from './routes/Recorder.svelte'
|
||||
import Settings from './routes/Settings.svelte'
|
||||
|
||||
@@ -21,9 +22,7 @@
|
||||
{:else if route === '/settings'}
|
||||
<Settings />
|
||||
{:else if route === '/prompt'}
|
||||
<main class="page">
|
||||
<p class="muted">Gespräch beendet.</p>
|
||||
</main>
|
||||
<Prompt />
|
||||
{:else}
|
||||
<main class="page">
|
||||
<header class="page-header">
|
||||
|
||||
@@ -40,6 +40,15 @@ export type RecordingState =
|
||||
| { state: 'idle' }
|
||||
| { state: 'recording'; call_id: CallId; app: string; started_at: string }
|
||||
|
||||
/** What the end-of-call prompt shows about a call. Times are RFC 3339. */
|
||||
export interface CallBrief {
|
||||
id: CallId
|
||||
app: string
|
||||
started_at: string
|
||||
ended_at: string | null
|
||||
duration_secs: number
|
||||
}
|
||||
|
||||
export interface Levels {
|
||||
mic: number
|
||||
out: number
|
||||
@@ -57,9 +66,15 @@ export const getRecordingState = () => invoke<RecordingState>('get_recording_sta
|
||||
export const startManualRecording = () => invoke<CallId>('start_manual_recording')
|
||||
export const stopRecording = () => invoke<void>('stop_recording')
|
||||
export const discardCurrentRecording = () => invoke<void>('discard_current_recording')
|
||||
export const getPendingPrompt = () => invoke<CallBrief | null>('get_pending_prompt')
|
||||
export const getCallBrief = (id: CallId) => invoke<CallBrief>('get_call_brief', { id })
|
||||
export const transcribeCall = (id: CallId) => invoke<void>('transcribe_call', { id })
|
||||
export const discardCall = (id: CallId) => invoke<void>('discard_call', { id })
|
||||
|
||||
export const onRecordingState = (handler: (state: RecordingState) => void): Promise<UnlistenFn> =>
|
||||
listen<RecordingState>('recording-state', (event) => handler(event.payload))
|
||||
export const onCallEnded = (handler: (id: CallId) => void): Promise<UnlistenFn> =>
|
||||
listen<{ id: CallId }>('call-ended', (event) => handler(event.payload.id))
|
||||
export const onLevels = (handler: (levels: Levels) => void): Promise<UnlistenFn> =>
|
||||
listen<Levels>('levels', (event) => handler(event.payload))
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// German display formats for calls ("Microsoft Teams · 32 min",
|
||||
// "heute, 10:14 – 10:46").
|
||||
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
|
||||
const clock = (d: Date) => `${pad(d.getHours())}:${pad(d.getMinutes())}`
|
||||
|
||||
const sameDay = (a: Date, b: Date) =>
|
||||
a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate()
|
||||
|
||||
/** Whole minutes, at least 1: "32 min". */
|
||||
export function formatMinutes(secs: number): string {
|
||||
return `${Math.max(1, Math.round(secs / 60))} min`
|
||||
}
|
||||
|
||||
/** "heute, 10:14 – 10:46", or "04.11., 10:14 – 10:46" for another day. */
|
||||
export function formatTimeRange(startedAt: string, endedAt: string | null, now = new Date()): string {
|
||||
const start = new Date(startedAt)
|
||||
const day = sameDay(start, now) ? 'heute' : `${pad(start.getDate())}.${pad(start.getMonth() + 1)}.`
|
||||
const range = endedAt ? `${clock(start)} – ${clock(new Date(endedAt))}` : clock(start)
|
||||
return `${day}, ${range}`
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte'
|
||||
import {
|
||||
discardCall,
|
||||
errorText,
|
||||
getCallBrief,
|
||||
getPendingPrompt,
|
||||
onCallEnded,
|
||||
transcribeCall,
|
||||
type CallBrief,
|
||||
type CallId,
|
||||
} from '../lib/api'
|
||||
import { formatMinutes, formatTimeRange } from '../lib/format'
|
||||
|
||||
let brief = $state<CallBrief | null>(null)
|
||||
let busy = $state(false)
|
||||
let error = $state('')
|
||||
|
||||
function show(next: CallBrief | null) {
|
||||
if (next?.id !== brief?.id) error = ''
|
||||
brief = next
|
||||
}
|
||||
|
||||
// The window stays loaded while hidden, so it may have missed the event:
|
||||
// ask the backend whenever it is shown again.
|
||||
const refresh = () =>
|
||||
getPendingPrompt()
|
||||
.then(show)
|
||||
.catch((err) => (error = errorText(err)))
|
||||
|
||||
const load = (id: CallId) =>
|
||||
getCallBrief(id)
|
||||
.then(show)
|
||||
.catch((err) => (error = errorText(err)))
|
||||
|
||||
onMount(() => {
|
||||
const unlisten = onCallEnded(load)
|
||||
refresh()
|
||||
window.addEventListener('focus', refresh)
|
||||
return () => {
|
||||
window.removeEventListener('focus', refresh)
|
||||
unlisten.then((off) => off())
|
||||
}
|
||||
})
|
||||
|
||||
async function run(action: (id: CallId) => Promise<void>) {
|
||||
if (!brief) return
|
||||
busy = true
|
||||
error = ''
|
||||
try {
|
||||
await action(brief.id)
|
||||
} catch (err) {
|
||||
error = errorText(err)
|
||||
} finally {
|
||||
busy = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<main class="prompt">
|
||||
{#if brief}
|
||||
<div class="title">{brief.app} · {formatMinutes(brief.duration_secs)}</div>
|
||||
<div class="muted">{formatTimeRange(brief.started_at, brief.ended_at)}</div>
|
||||
<div class="actions">
|
||||
<button class="btn primary" disabled={busy} onclick={() => run(transcribeCall)}>
|
||||
Transkribieren
|
||||
</button>
|
||||
<button class="btn danger" disabled={busy} onclick={() => run(discardCall)}>Verwerfen</button>
|
||||
</div>
|
||||
{:else}
|
||||
<p class="muted">Kein Gespräch wartet auf eine Entscheidung.</p>
|
||||
{/if}
|
||||
{#if error}
|
||||
<div class="error">{error}</div>
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
<style>
|
||||
:global(body:has(.prompt)) {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.prompt {
|
||||
min-height: 100vh;
|
||||
background: var(--surface);
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin-top: 8px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user