Skip to content

Commit b0a0817

Browse files
committed
fix: prevent model auto-switch from interrupting active transcription
when a model download completes during an active recording/transcription, the app now skips auto-switching to prevent data loss. adds is_recording tauri command to check recording state before auto-switching models on download or extraction completion. fixes #418
1 parent 8ac98b3 commit b0a0817

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src-tauri/src/commands/audio.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,10 @@ pub fn get_clamshell_microphone(app: AppHandle) -> Result<String, String> {
193193
.clamshell_microphone
194194
.unwrap_or_else(|| "default".to_string()))
195195
}
196+
197+
#[tauri::command]
198+
#[specta::specta]
199+
pub fn is_recording(app: AppHandle) -> bool {
200+
let audio_manager = app.state::<Arc<AudioRecordingManager>>();
201+
audio_manager.is_recording()
202+
}

src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ pub fn run() {
296296
commands::audio::check_custom_sounds,
297297
commands::audio::set_clamshell_microphone,
298298
commands::audio::get_clamshell_microphone,
299+
commands::audio::is_recording,
299300
commands::transcription::set_model_unload_timeout,
300301
commands::transcription::get_model_load_status,
301302
commands::transcription::unload_model_manually,

src/bindings.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,14 @@ async getClamshellMicrophone() : Promise<Result<string, string>> {
517517
else return { status: "error", error: e as any };
518518
}
519519
},
520+
async isRecording() : Promise<Result<boolean, string>> {
521+
try {
522+
return { status: "ok", data: await TAURI_INVOKE("is_recording") };
523+
} catch (e) {
524+
if(e instanceof Error) throw e;
525+
else return { status: "error", error: e as any };
526+
}
527+
},
520528
async setModelUnloadTimeout(timeout: ModelUnloadTimeout) : Promise<void> {
521529
await TAURI_INVOKE("set_model_unload_timeout", { timeout });
522530
},

src/components/model-selector/ModelSelector.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,12 @@ const ModelSelector: React.FC<ModelSelectorProps> = ({ onError }) => {
164164
});
165165
loadModels(); // Refresh models list
166166

167-
// Auto-select the newly downloaded model
168-
setTimeout(() => {
167+
// Auto-select the newly downloaded model (skip if recording in progress)
168+
setTimeout(async () => {
169+
const recordingResult = await commands.isRecording();
170+
if (recordingResult.status === "ok" && recordingResult.data) {
171+
return; // Skip auto-switch if recording in progress
172+
}
169173
loadCurrentModel();
170174
handleModelSelect(modelId);
171175
}, 500);
@@ -193,8 +197,12 @@ const ModelSelector: React.FC<ModelSelectorProps> = ({ onError }) => {
193197
});
194198
loadModels(); // Refresh models list
195199

196-
// Auto-select the newly extracted model
197-
setTimeout(() => {
200+
// Auto-select the newly extracted model (skip if recording in progress)
201+
setTimeout(async () => {
202+
const recordingResult = await commands.isRecording();
203+
if (recordingResult.status === "ok" && recordingResult.data) {
204+
return; // Skip auto-switch if recording in progress
205+
}
198206
loadCurrentModel();
199207
handleModelSelect(modelId);
200208
}, 500);

0 commit comments

Comments
 (0)