Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src-tauri/src/dictation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,28 @@ fn trigger_microphone_permission_request() -> Result<(), String> {
/// Returns Ok(true) if permission was granted, Ok(false) if denied,
/// or Err with a message if the request failed.
#[cfg(target_os = "macos")]
async fn request_microphone_permission() -> Result<bool, String> {
async fn request_microphone_permission(app: &AppHandle) -> Result<bool, String> {
let status = check_microphone_authorization()?;

match status {
AVAuthorizationStatus::Authorized => Ok(true),
AVAuthorizationStatus::Denied | AVAuthorizationStatus::Restricted => Ok(false),
AVAuthorizationStatus::NotDetermined | _ => {
// Trigger the permission request (this shows the system dialog)
// We do this in a sync context to avoid RcBlock Send issues
trigger_microphone_permission_request()?;
// Ensure we do this on the main thread so the system dialog appears.
let (tx, rx) = oneshot::channel();
let app_handle = app.clone();
app_handle
.run_on_main_thread(move || {
let _ = tx.send(trigger_microphone_permission_request());
})
.map_err(|error| error.to_string())?;

match rx.await {
Ok(Ok(())) => {}
Ok(Err(error)) => return Err(error),
Err(_) => return Err("Failed to request microphone permission.".to_string()),
}

// Poll the authorization status until it changes from NotDetermined
let mut attempts = 0;
Expand All @@ -84,7 +96,7 @@ async fn request_microphone_permission() -> Result<bool, String> {
}

#[cfg(not(target_os = "macos"))]
async fn request_microphone_permission() -> Result<bool, String> {
async fn request_microphone_permission(_app: &AppHandle) -> Result<bool, String> {
// On non-macOS platforms, assume permission is granted
// (Linux doesn't have the same permission model)
Ok(true)
Expand Down Expand Up @@ -750,7 +762,7 @@ pub(crate) async fn dictation_start(
}

// Request microphone permission before attempting to capture audio
match request_microphone_permission().await {
match request_microphone_permission(&app).await {
Ok(true) => {
// Permission granted, continue
}
Expand Down