Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(macOS): prevent window focus and mic grant callbacks from re-enabling recording (#5909)

JQuantc70da85ba064
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index bfeb2ead7..171e4f76a 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -806,6 +806,13 @@ async fn main() {
tauri::WindowEvent::Focused(true) => {
let app = window.app_handle().clone();
tauri::async_runtime::spawn(async move {
+ let capture_intended = app
+ .try_state::<RecordingState>()
+ .map(|s| s.capture_intended())
+ .unwrap_or(false);
+ if !capture_intended {
+ return;
+ }
let permission_granted =
permissions::check_microphone_permission().permitted();
let audio_devices_empty = health::get_audio_device_status().is_empty();
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs b/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs
index 8758041e0..d3ea6ae7c 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs
@@ -295,6 +295,15 @@ fn request_av_permission(app: tauri::AppHandle, media_type: nokhwa_bindings_maco
let callback = move |granted: BOOL| {
if is_audio && granted != NO {
+ use tauri::Manager;
+ let capture_intended = app_for_callback
+ .try_state::<crate::recording::RecordingState>()
+ .map(|s| s.capture_intended())
+ .unwrap_or(false);
+ if !capture_intended {
+ debug!("Microphone permission granted via AV callback — capture not intended, skipping restart");
+ return;
+ }
info!(
"Microphone permission granted via AV callback — restarting capture for audio reinit"
);
@@ -357,6 +366,15 @@ const BOOT_WAIT_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30
pub(crate) async fn restart_capture_on_mic_grant(app: tauri::AppHandle) {
use tauri::Manager;
+ let capture_intended = app
+ .try_state::<crate::recording::RecordingState>()
+ .map(|s| s.capture_intended())
+ .unwrap_or(false);
+ if !capture_intended {
+ debug!("start_capture after mic grant: capture not intended (user disabled recording), skipping restart");
+ return;
+ }
+
if MIC_GRANT_RESTART_IN_FLIGHT
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
.is_err()