From 933be7cd45c8b31ea8c9620436907293da4d0bdd Mon Sep 17 00:00:00 2001 From: Louis Beaumont Date: Tue, 27 Aug 2024 12:43:19 +0200 Subject: [PATCH] feat: add open permission button for macos --- .../components/screenpipe-status.tsx | 71 ++++++++++++++++--- .../src-tauri/src/commands.rs | 45 ++++++++++++ .../src-tauri/src/main.rs | 6 ++ 3 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 examples/apps/screenpipe-app-tauri/src-tauri/src/commands.rs diff --git a/examples/apps/screenpipe-app-tauri/components/screenpipe-status.tsx b/examples/apps/screenpipe-app-tauri/components/screenpipe-status.tsx index 75e23fc0..ea048b66 100644 --- a/examples/apps/screenpipe-app-tauri/components/screenpipe-status.tsx +++ b/examples/apps/screenpipe-app-tauri/components/screenpipe-status.tsx @@ -26,6 +26,7 @@ import { Separator } from "./ui/separator"; import { Card, CardContent, CardFooter } from "./ui/card"; import { useHealthCheck } from "@/lib/hooks/use-health-check"; import { DevSettings } from "./dev-dialog"; +import { Lock } from "lucide-react"; const getDebuggingCommands = (os: string | null) => { let cliInstructions = ""; @@ -317,18 +318,44 @@ const DevModeSettings = () => { ); }; -interface HealthCheckResponse { - status: string; - last_frame_timestamp: string | null; - last_audio_timestamp: string | null; - frame_status: string; - audio_status: string; - message: string; -} - const HealthStatus = ({ className }: { className?: string }) => { const { health } = useHealthCheck(); const [isDialogOpen, setIsDialogOpen] = useState(false); + const [isMac, setIsMac] = useState(false); + + useEffect(() => { + setIsMac(platform() === "macos"); + }, []); + + const handleResetScreenPermissions = async () => { + const toastId = toast({ + title: "opening permissions", + description: "please wait...", + duration: Infinity, + }); + + try { + await invoke("open_screen_capture_preferences"); + await new Promise((resolve) => setTimeout(resolve, 2000)); + + toastId.update({ + id: toastId.id, + title: "permissions reset", + description: + "screen capture permissions have been reset. please restart the app.", + duration: 5000, + }); + } catch (error) { + console.error("failed to reset screen permissions:", error); + toastId.update({ + id: toastId.id, + title: "error", + description: "failed to reset screen permissions.", + variant: "destructive", + duration: 3000, + }); + } + }; const getStatusColor = (status: string) => { switch (status) { @@ -395,8 +422,8 @@ const HealthStatus = ({ className }: { className?: string }) => {

last audio: {formatTimestamp(health.last_audio_timestamp)}

-
-

troubleshooting Instructions:

+
+

troubleshooting instructions:

{`if you're experiencing issues, please try the following steps: 1. restart screenpipe @@ -404,6 +431,28 @@ const HealthStatus = ({ className }: { className?: string }) => { 3. if the problem persists, please contact support at [louis@screenpi.pe](mailto:louis@screenpi.pe) or @louis030195 on Discord, X, or LinkedIn 4. last, here are some [FAQ](https://github.com/mediar-ai/screenpipe/blob/main/content/docs/NOTES.md) with visuals to help you troubleshoot`} + {isMac && ( +
+ + + + + + +

open screen capture permissions

+
+
+
+
+ )}
diff --git a/examples/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/examples/apps/screenpipe-app-tauri/src-tauri/src/commands.rs new file mode 100644 index 00000000..f367b03f --- /dev/null +++ b/examples/apps/screenpipe-app-tauri/src-tauri/src/commands.rs @@ -0,0 +1,45 @@ + +// #[tauri::command] +// pub fn has_screen_capture_access() -> bool { +// scap::has_permission() +// } + +#[tauri::command] +pub fn open_screen_capture_preferences() { + #[cfg(target_os = "macos")] + std::process::Command::new("open") + .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture") + .spawn() + .expect("failed to open system preferences"); +} + +#[tauri::command] +pub fn open_mic_preferences() { + #[cfg(target_os = "macos")] + std::process::Command::new("open") + .arg("x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone") + .spawn() + .expect("failed to open system preferences"); +} + +#[tauri::command] +pub fn reset_screen_permissions() { + #[cfg(target_os = "macos")] + std::process::Command::new("tccutil") + .arg("reset") + .arg("ScreenCapture") + .arg("so.cap.desktop") + .spawn() + .expect("failed to reset screen permissions"); +} + +#[tauri::command] +pub fn reset_microphone_permissions() { + #[cfg(target_os = "macos")] + std::process::Command::new("tccutil") + .arg("reset") + .arg("Microphone") + .arg("so.cap.desktop") + .spawn() + .expect("failed to reset microphone permissions"); +} diff --git a/examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs index 919686fb..7a6b5ba5 100755 --- a/examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs +++ b/examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs @@ -35,6 +35,10 @@ mod analytics; use crate::analytics::start_analytics; +mod commands; + +pub use commands::reset_screen_permissions; +pub use commands::open_screen_capture_preferences; struct SidecarState(Arc>>); #[tauri::command] @@ -351,6 +355,8 @@ async fn main() { .invoke_handler(tauri::generate_handler![ spawn_screenpipe, kill_all_sreenpipes, + reset_screen_permissions, + open_screen_capture_preferences, ]) .setup(|app| { // Logging setup