Skip to content

Commit b31a41a

Browse files
fix: prevent model auto-switch from interrupting active transcription (#443)
* 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 * Update bindings.ts --------- Co-authored-by: CJ Pais <[email protected]>
1 parent 5f7ffe1 commit b31a41a

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@ async getClamshellMicrophone() : Promise<Result<string, string>> {
517517
else return { status: "error", error: e as any };
518518
}
519519
},
520+
async isRecording() : Promise<boolean> {
521+
return await TAURI_INVOKE("is_recording");
522+
},
520523
async setModelUnloadTimeout(timeout: ModelUnloadTimeout) : Promise<void> {
521524
await TAURI_INVOKE("set_model_unload_timeout", { timeout });
522525
},

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)