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

Borrow permission monitor reasons (#4039)

Louis Beaumont2a8657908c9e
diff --git a/crates/screenpipe-engine/src/permission_monitor.rs b/crates/screenpipe-engine/src/permission_monitor.rs
index d93a14026..defdd6e4a 100644
--- a/crates/screenpipe-engine/src/permission_monitor.rs
+++ b/crates/screenpipe-engine/src/permission_monitor.rs
@@ -142,7 +142,7 @@ pub fn start() -> Option<JoinHandle<()>> {
///
/// Skipped silently during the wake grace period to avoid spurious
/// lost→restored flashes after sleep/wake.
-pub fn report_state(kind: PermissionKind, now_granted: bool, reason: Option<String>) {
+pub fn report_state(kind: PermissionKind, now_granted: bool, reason: Option<&str>) {
let mut state = STATE.lock().unwrap_or_else(|e| e.into_inner());
// Suppress emissions during wake grace period. A real transition will
@@ -195,10 +195,10 @@ pub fn report_state(kind: PermissionKind, now_granted: bool, reason: Option<Stri
} else {
info!(
?kind,
- reason = reason.as_deref().unwrap_or("(unknown)"),
+ reason = reason.unwrap_or("(unknown)"),
"permission lost"
);
- PermissionEvent::lost(kind, reason)
+ PermissionEvent::lost(kind, reason.map(str::to_owned))
};
let _ = send_event(evt.event_name(), evt);
}
@@ -226,22 +226,22 @@ async fn run() {
report_state(
PermissionKind::ScreenRecording,
granted(perms.screen_recording),
- Some("poll".to_string()),
+ Some("poll"),
);
report_state(
PermissionKind::Microphone,
granted(perms.microphone),
- Some("poll".to_string()),
+ Some("poll"),
);
report_state(
PermissionKind::Accessibility,
granted(perms.accessibility),
- Some("poll".to_string()),
+ Some("poll"),
);
report_state(
PermissionKind::Keychain,
keychain_accessible(),
- Some("poll".to_string()),
+ Some("poll"),
);
}
}
diff --git a/crates/screenpipe-engine/src/vision_manager/monitor_watcher.rs b/crates/screenpipe-engine/src/vision_manager/monitor_watcher.rs
index 44f69b804..916a29027 100644
--- a/crates/screenpipe-engine/src/vision_manager/monitor_watcher.rs
+++ b/crates/screenpipe-engine/src/vision_manager/monitor_watcher.rs
@@ -133,7 +133,7 @@ pub async fn start_monitor_watcher(
permission_monitor::report_state(
PermissionKind::ScreenRecording,
false,
- Some("list_monitors PermissionDenied (startup)".to_string()),
+ Some("list_monitors PermissionDenied (startup)"),
);
}
Err(e) => {
@@ -364,7 +364,7 @@ pub async fn start_monitor_watcher(
permission_monitor::report_state(
PermissionKind::ScreenRecording,
false,
- Some("list_monitors PermissionDenied (runtime)".to_string()),
+ Some("list_monitors PermissionDenied (runtime)"),
);
}
// Back off to 30s when permission is denied instead of 2s