Skip to content

Commit 2225a86

Browse files
committed
Refactor mic input selection logic in set_mic_input
1 parent fcd44c0 commit 2225a86

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

  • apps/desktop/src-tauri/src

apps/desktop/src-tauri/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,10 @@ impl App {
236236
#[specta::specta]
237237
#[instrument(skip(state))]
238238
async fn set_mic_input(state: MutableState<'_, App>, label: Option<String>) -> Result<(), String> {
239-
let mic_feed = {
240-
let mut app = state.write().await;
241-
app.selected_mic_label = label.clone();
242-
app.mic_feed.clone()
243-
};
239+
let mic_feed = state.read().await.mic_feed.clone();
240+
let desired_label = label.clone();
244241

245-
match label {
242+
match desired_label.as_ref() {
246243
None => {
247244
mic_feed
248245
.ask(microphone::RemoveInput)
@@ -251,14 +248,21 @@ async fn set_mic_input(state: MutableState<'_, App>, label: Option<String>) -> R
251248
}
252249
Some(label) => {
253250
mic_feed
254-
.ask(feeds::microphone::SetInput { label })
251+
.ask(feeds::microphone::SetInput {
252+
label: label.clone(),
253+
})
255254
.await
256255
.map_err(|e| e.to_string())?
257256
.await
258257
.map_err(|e| e.to_string())?;
259258
}
260259
}
261260

261+
{
262+
let mut app = state.write().await;
263+
app.selected_mic_label = desired_label;
264+
}
265+
262266
Ok(())
263267
}
264268

0 commit comments

Comments
 (0)