Skip to content

Commit

Permalink
feat: add open permission button for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Aug 27, 2024
1 parent ece5214 commit 933be7c
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 11 deletions.
71 changes: 60 additions & 11 deletions examples/apps/screenpipe-app-tauri/components/screenpipe-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -395,15 +422,37 @@ const HealthStatus = ({ className }: { className?: string }) => {
<p className="text-xs mb-1">
last audio: {formatTimestamp(health.last_audio_timestamp)}
</p>
<div className="text-xs mt-2">
<p className="font-bold mb-1">troubleshooting Instructions:</p>
<div className="text-xs mt-2 relative">
<p className="font-bold mb-1">troubleshooting instructions:</p>
<MarkdownWithExternalLinks className="prose prose-sm">
{`if you're experiencing issues, please try the following steps:
1. restart screenpipe
2. reset your screenpipe OS audio/screen recording permissions
3. if the problem persists, please contact support at [[email protected]](mailto:[email protected]) 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`}
</MarkdownWithExternalLinks>
{isMac && (
<div className="absolute top-[6.5em] right-0">
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="sm"
onClick={handleResetScreenPermissions}
className="flex-shrink-0"
>
<Lock className="h-4 w-4 mr-2" />
open permissions
</Button>
</TooltipTrigger>
<TooltipContent>
<p>open screen capture permissions</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
)}
</div>
<Separator className="my-4" />
<DevModeSettings />
Expand Down
45 changes: 45 additions & 0 deletions examples/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
@@ -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");
}
6 changes: 6 additions & 0 deletions examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex<Option<CommandChild>>>);

#[tauri::command]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 933be7c

Please sign in to comment.