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,76 @@
|
||||
// Typed wrappers around the Tauri commands and events of the app shell.
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
||||
|
||||
export type CallId = number
|
||||
|
||||
export interface Settings {
|
||||
allowlist: string[]
|
||||
mic_device: string | null
|
||||
output_device: string | null
|
||||
language: string
|
||||
deepscript_model: string
|
||||
retention_days: number
|
||||
autostart: boolean
|
||||
start_after_secs: number
|
||||
end_after_secs: number
|
||||
}
|
||||
|
||||
export type Service = 'deepscript' | 'anthropic'
|
||||
|
||||
export interface DeviceInfo {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface Devices {
|
||||
inputs: DeviceInfo[]
|
||||
outputs: DeviceInfo[]
|
||||
}
|
||||
|
||||
export interface DeviceLevels {
|
||||
mic: number
|
||||
out: number
|
||||
}
|
||||
|
||||
export type Track = 'mic' | 'out'
|
||||
|
||||
export type RecordingState =
|
||||
| { state: 'idle' }
|
||||
| { state: 'recording'; call_id: CallId; app: string; started_at: string }
|
||||
|
||||
export interface Levels {
|
||||
mic: number
|
||||
out: number
|
||||
failed_tracks: Track[]
|
||||
}
|
||||
|
||||
export const getSettings = () => invoke<Settings>('get_settings')
|
||||
export const saveSettings = (settings: Settings) => invoke<void>('save_settings', { settings })
|
||||
export const setApiKey = (service: Service, key: string) =>
|
||||
invoke<void>('set_api_key', { service, key })
|
||||
export const hasApiKey = (service: Service) => invoke<boolean>('has_api_key', { service })
|
||||
export const listDevices = () => invoke<Devices>('list_devices')
|
||||
export const testDevices = () => invoke<DeviceLevels>('test_devices')
|
||||
export const getRecordingState = () => invoke<RecordingState>('get_recording_state')
|
||||
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 onRecordingState = (handler: (state: RecordingState) => void): Promise<UnlistenFn> =>
|
||||
listen<RecordingState>('recording-state', (event) => handler(event.payload))
|
||||
export const onLevels = (handler: (levels: Levels) => void): Promise<UnlistenFn> =>
|
||||
listen<Levels>('levels', (event) => handler(event.payload))
|
||||
|
||||
/** Maps an rms level (0..1) to a meter fill (0..1) on a -60..0 dB scale. */
|
||||
export function meterFill(level: number): number {
|
||||
if (level <= 0) return 0
|
||||
const db = 20 * Math.log10(level)
|
||||
return Math.min(1, Math.max(0, (db + 60) / 60))
|
||||
}
|
||||
|
||||
/** Error text of a rejected command. */
|
||||
export function errorText(err: unknown): string {
|
||||
return typeof err === 'string' ? err : err instanceof Error ? err.message : String(err)
|
||||
}
|
||||
Reference in New Issue
Block a user