diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 750b79f..cc4c4d3 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -355,12 +355,21 @@ pub fn show_main(app: &AppHandle) { show_and_focus(app, "main"); } -/// Brings the floating window to the front (tray "Aufnahme manuell -/// starten" while a recording runs). -pub fn show_recorder(app: &AppHandle) { +/// Brings the floating window to the front: the tray's "Aufnahme manuell +/// starten" and the main window's record button both call this instead of +/// starting a second recording when one is already running. +pub fn focus_recorder(app: &AppHandle) { show_and_focus(app, "recorder"); } +/// Main window record button while a recording already runs: shows/focuses +/// the floating recorder window instead of starting another recording. +/// Shares [`focus_recorder`] with the tray handler. +#[tauri::command] +pub fn show_recorder(app: AppHandle) { + focus_recorder(&app); +} + fn show_and_focus(app: &AppHandle, label: &str) { if let Some(window) = app.get_webview_window(label) { let _ = window.unminimize(); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index bf5cbf8..c136661 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -123,6 +123,7 @@ pub fn run() { commands::test_devices, commands::get_recording_state, commands::start_manual_recording, + commands::show_recorder, commands::stop_recording, commands::discard_current_recording, commands::get_pending_prompt, diff --git a/src-tauri/src/tray.rs b/src-tauri/src/tray.rs index 2bfc588..eeaf916 100644 --- a/src-tauri/src/tray.rs +++ b/src-tauri/src/tray.rs @@ -38,7 +38,7 @@ pub fn create(app: &AppHandle) -> tauri::Result<()> { app.state::().recording_state(), RecordingState::Recording { .. } ) { - commands::show_recorder(app); + commands::focus_recorder(app); return; } // Opening the audio devices can take a moment; keep the diff --git a/ui/src/lib/api.ts b/ui/src/lib/api.ts index 8470436..b1deb2a 100644 --- a/ui/src/lib/api.ts +++ b/ui/src/lib/api.ts @@ -128,6 +128,8 @@ export const listDevices = () => invoke('list_devices') export const testDevices = () => invoke('test_devices') export const getRecordingState = () => invoke('get_recording_state') export const startManualRecording = () => invoke('start_manual_recording') +/** Shows/focuses the floating recorder window instead of starting another recording. */ +export const showRecorder = () => invoke('show_recorder') export const stopRecording = () => invoke('stop_recording') export const discardCurrentRecording = () => invoke('discard_current_recording') export const getPendingPrompt = () => invoke('get_pending_prompt') diff --git a/ui/src/routes/Main.svelte b/ui/src/routes/Main.svelte index 0de4626..93890f8 100644 --- a/ui/src/routes/Main.svelte +++ b/ui/src/routes/Main.svelte @@ -4,6 +4,7 @@ discardCall, errorText, getCall, + getRecordingState, listAccounts, listCalls, mergeSpeakers, @@ -15,12 +16,15 @@ renameSpeaker, retryCall, setAccount, + showRecorder, + startManualRecording, transcribeCall, unmergeSpeaker, type Account, type CallDetail, type CallId, type CallListItem, + type RecordingState, } from '../lib/api' import CallList from '../lib/CallList.svelte' import { formatDetailTime, formatMinutes } from '../lib/format' @@ -33,6 +37,10 @@ let listError = $state('') let accounts = $state([]) + let recordingState = $state({ state: 'idle' }) + let recordBusy = $state(false) + let recordError = $state('') + let selectedId = $state(null) let detail = $state(null) let detailError = $state('') @@ -115,15 +123,45 @@ }), onCallEnded(refreshList), onPromptChanged(refreshList), - onRecordingState(refreshList), + onRecordingState((state) => { + recordingState = state + refreshList() + }), ] refreshList() + getRecordingState() + .then((state) => (recordingState = state)) + .catch((err) => (recordError = errorText(err))) listAccounts() .then((list) => (accounts = list)) .catch((err) => (listError = errorText(err))) return () => unlisten.forEach((u) => u.then((off) => off())) }) + /** The record button: starts a manual recording, or shows the floating + * recorder window if one already runs (same as the tray entry). Errors + * (e.g. "Es läuft bereits eine Aufnahme", device errors) show inline in + * the sidebar header. */ + async function recordClick() { + recordError = '' + if (recordingState.state === 'recording') { + try { + await showRecorder() + } catch (err) { + recordError = errorText(err) + } + return + } + recordBusy = true + try { + await startManualRecording() + } catch (err) { + recordError = errorText(err) + } finally { + recordBusy = false + } + } + /** Runs a command on the shown call; its error is shown inline. */ async function run(action: (id: CallId) => Promise, done?: () => void) { if (!detail) return @@ -235,8 +273,23 @@