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: prevent duplicate permission_lost events

Louis Beaumont0dd556c23e59
diff --git a/Cargo.lock b/Cargo.lock
index e7527b48a..996654753 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6628,7 +6628,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.36"
+version = "0.3.37"
dependencies = [
"anyhow",
"bytemuck",
@@ -6681,7 +6681,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.36"
+version = "0.3.37"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -6732,7 +6732,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.36"
+version = "0.3.37"
dependencies = [
"anyhow",
"chrono",
@@ -6756,7 +6756,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.36"
+version = "0.3.37"
dependencies = [
"anyhow",
"chrono",
@@ -6774,7 +6774,7 @@ dependencies = [
[[package]]
name = "screenpipe-integrations"
-version = "0.3.36"
+version = "0.3.37"
dependencies = [
"anyhow",
"image",
@@ -6789,7 +6789,7 @@ dependencies = [
[[package]]
name = "screenpipe-server"
-version = "0.3.36"
+version = "0.3.37"
dependencies = [
"anyhow",
"async-trait",
@@ -6858,7 +6858,7 @@ dependencies = [
[[package]]
name = "screenpipe-vision"
-version = "0.3.36"
+version = "0.3.37"
dependencies = [
"accessibility-sys",
"anyhow",
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-permission-monitor.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-permission-monitor.tsx
index 4af237def..88bdb7a4e 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-permission-monitor.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-permission-monitor.tsx
@@ -1,6 +1,7 @@
"use client";
import { useEffect, useRef } from "react";
+import { usePathname } from "next/navigation";
import { listen } from "@tauri-apps/api/event";
import { commands } from "@/lib/utils/tauri";
import posthog from "posthog-js";
@@ -17,11 +18,17 @@ interface PermissionLostPayload {
*/
export function usePermissionMonitor() {
const hasShownRef = useRef(false);
+ const pathname = usePathname();
useEffect(() => {
// Only run on client side
if (typeof window === "undefined") return;
+ // Only run permission monitor on main app pages, not overlays or onboarding
+ // This prevents duplicate PostHog events since each Tauri window runs its own instance
+ const skipPaths = ["/shortcut-reminder", "/onboarding", "/permission-recovery"];
+ if (skipPaths.some((p) => pathname?.startsWith(p))) return;
+
const unlisten = listen<PermissionLostPayload>("permission-lost", async (event) => {
const { screen_recording, microphone, accessibility } = event.payload;
@@ -75,7 +82,7 @@ export function usePermissionMonitor() {
return () => {
unlisten.then((fn) => fn());
};
- }, []);
+ }, [pathname]);
}
/**
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index 314056996..c75a6a88e 100755
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -8612,7 +8612,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.0.239"
+version = "2.0.243"
dependencies = [
"anyhow",
"async-stream",
@@ -8692,7 +8692,7 @@ dependencies = [
[[package]]
name = "screenpipe-audio"
-version = "0.3.33"
+version = "0.3.37"
dependencies = [
"anyhow",
"bytemuck",
@@ -8740,7 +8740,7 @@ dependencies = [
[[package]]
name = "screenpipe-core"
-version = "0.3.33"
+version = "0.3.37"
dependencies = [
"accessibility",
"accessibility-sys",
@@ -8791,7 +8791,7 @@ dependencies = [
[[package]]
name = "screenpipe-db"
-version = "0.3.33"
+version = "0.3.37"
dependencies = [
"anyhow",
"chrono",
@@ -8815,7 +8815,7 @@ dependencies = [
[[package]]
name = "screenpipe-events"
-version = "0.3.33"
+version = "0.3.37"
dependencies = [
"anyhow",
"chrono",
@@ -8831,7 +8831,7 @@ dependencies = [
[[package]]
name = "screenpipe-integrations"
-version = "0.3.33"
+version = "0.3.37"
dependencies = [
"anyhow",
"image 0.25.5",
@@ -8846,7 +8846,7 @@ dependencies = [
[[package]]
name = "screenpipe-server"
-version = "0.3.33"
+version = "0.3.37"
dependencies = [
"anyhow",
"async-trait",
@@ -8910,7 +8910,7 @@ dependencies = [
[[package]]
name = "screenpipe-vision"
-version = "0.3.33"
+version = "0.3.37"
dependencies = [
"accessibility-sys",
"anyhow",
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs b/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs
index 2d0e23082..654de2ed1 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/permissions.rs
@@ -340,8 +340,22 @@ pub fn do_permissions_check(initial_check: bool) -> OSPermissionsCheck {
pub async fn start_permission_monitor(app: tauri::AppHandle) {
use tokio::time::{interval, Duration};
use tauri::Emitter;
+ use crate::store::OnboardingStore;
- // Wait a bit before starting to monitor (let the app initialize)
+ // Wait for onboarding to complete before monitoring permissions
+ // During onboarding, permissions haven't been granted yet - monitoring would cause false alarms
+ loop {
+ tokio::time::sleep(Duration::from_secs(5)).await;
+ match OnboardingStore::get(&app) {
+ Ok(Some(store)) if store.is_completed => {
+ info!("onboarding completed, starting permission monitor");
+ break;
+ }
+ _ => continue,
+ }
+ }
+
+ // Extra delay after onboarding to let permissions settle
tokio::time::sleep(Duration::from_secs(10)).await;
let mut check_interval = interval(Duration::from_secs(30));
@@ -392,21 +406,25 @@ pub async fn start_permission_monitor(app: tauri::AppHandle) {
let accessibility_confirmed_lost = accessibility_fail_count == REQUIRED_CONSECUTIVE_FAILURES;
if screen_confirmed_lost || mic_confirmed_lost || accessibility_confirmed_lost {
- warn!(
- "permission confirmed lost after {} consecutive failures - screen: {} (fails: {}), mic: {} (fails: {}), accessibility: {} (fails: {})",
- REQUIRED_CONSECUTIVE_FAILURES,
- screen_ok, screen_fail_count,
- mic_ok, mic_fail_count,
- accessibility_ok, accessibility_fail_count
- );
-
- // Emit event to frontend
- if let Err(e) = app.emit("permission-lost", serde_json::json!({
- "screen_recording": !screen_ok,
- "microphone": !mic_ok,
- "accessibility": !accessibility_ok,
- })) {
- error!("failed to emit permission-lost event: {}", e);
+ // Double-check: only emit if at least one permission is actually lost right now
+ // This prevents phantom events from transient TCC flickers
+ if !screen_ok || !mic_ok || !accessibility_ok {
+ warn!(
+ "permission confirmed lost after {} consecutive failures - screen: {} (fails: {}), mic: {} (fails: {}), accessibility: {} (fails: {})",
+ REQUIRED_CONSECUTIVE_FAILURES,
+ screen_ok, screen_fail_count,
+ mic_ok, mic_fail_count,
+ accessibility_ok, accessibility_fail_count
+ );
+
+ // Emit event to frontend
+ if let Err(e) = app.emit("permission-lost", serde_json::json!({
+ "screen_recording": !screen_ok,
+ "microphone": !mic_ok,
+ "accessibility": !accessibility_ok,
+ })) {
+ error!("failed to emit permission-lost event: {}", e);
+ }
}
}