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

release-app make permission simpler, more reactive

Louis Beaumontde935b38d40a
diff --git a/screenpipe-app-tauri/components/pipe-store.tsx b/screenpipe-app-tauri/components/pipe-store.tsx
index 30ec03eae..4a311aa3e 100644
--- a/screenpipe-app-tauri/components/pipe-store.tsx
+++ b/screenpipe-app-tauri/components/pipe-store.tsx
@@ -30,13 +30,15 @@ import {
} from "@/components/ui/tooltip";
import localforage from "localforage";
import { useLoginDialog } from "./login-dialog";
+import { PermissionButtons } from "./status/permission-buttons";
+import { usePlatform } from "@/lib/hooks/use-platform";
const corePipes: string[] = ["data-table", "search"];
export const PipeStore: React.FC = () => {
const { health } = useHealthCheck();
const [selectedPipe, setSelectedPipe] = useState<PipeWithStatus | null>(null);
- const { settings, loadUser } = useSettings();
+ const { settings } = useSettings();
const [pipes, setPipes] = useState<PipeWithStatus[]>([]);
const [installedPipes, setInstalledPipes] = useState<InstalledPipe[]>([]);
const [searchQuery, setSearchQuery] = useState("");
@@ -52,7 +54,7 @@ export const PipeStore: React.FC = () => {
const [loadingInstalls, setLoadingInstalls] = useState<Set<string>>(
new Set()
);
-
+ const { isMac: isMacOS } = usePlatform();
const filteredPipes = pipes
.filter(
(pipe) =>
@@ -997,7 +999,7 @@ export const PipeStore: React.FC = () => {
if (health?.status === "error") {
return (
<div className="flex flex-col items-center justify-center h-screen p-4 space-y-4">
- <div className="text-center space-y-4">
+ <div className="text-center space-y-4 max-w-md mx-auto justify-center items-center">
<h3 className="text-lg font-medium">screenpipe is not recording</h3>
<p className="text-sm text-muted-foreground">
please start the screenpipe service to browse and manage pipes
@@ -1010,6 +1012,17 @@ export const PipeStore: React.FC = () => {
<Power className="h-4 w-4" />
check service status
</Button>
+
+ {isMacOS && (
+ <div className="mt-6 pt-4 border-t w-full flex flex-col items-center">
+ <h4 className="text-sm font-medium mb-3">check permissions</h4>
+ <div className="space-y-2">
+ <PermissionButtons settings={settings} type="screen" />
+ <PermissionButtons settings={settings} type="audio" />
+ <PermissionButtons settings={settings} type="accessibility" />
+ </div>
+ </div>
+ )}
</div>
</div>
);
diff --git a/screenpipe-app-tauri/components/screenpipe-status.tsx b/screenpipe-app-tauri/components/screenpipe-status.tsx
index 23886ffd5..61cbc2f8b 100644
--- a/screenpipe-app-tauri/components/screenpipe-status.tsx
+++ b/screenpipe-app-tauri/components/screenpipe-status.tsx
@@ -1,5 +1,5 @@
"use client";
-import React, { useState, useEffect } from "react";
+import React, { useState } from "react";
import {
Dialog,
DialogContent,
@@ -7,65 +7,26 @@ import {
DialogTitle,
} from "@/components/ui/dialog";
import { Badge } from "./ui/badge";
-import { invoke } from "@tauri-apps/api/core";
import { toast } from "./ui/use-toast";
import { Button } from "./ui/button";
import { Separator } from "./ui/separator";
import { useHealthCheck } from "@/lib/hooks/use-health-check";
-import { Lock, Folder, Activity, Power } from "lucide-react";
+import { Lock, Folder, Power, Settings } from "lucide-react";
import { open as openUrl } from "@tauri-apps/plugin-shell";
import { LogFileButton } from "./log-file-button";
import { DevModeSettings } from "./dev-mode-settings";
import { cn } from "@/lib/utils";
-import { Check, X } from "lucide-react";
import { useSettings } from "@/lib/hooks/use-settings";
import { useStatusDialog } from "@/lib/hooks/use-status-dialog";
-import { platform } from "@tauri-apps/plugin-os";
-
-type PermissionsStatus = {
- screenRecording: string;
- microphone: string;
- accessibility: string;
-};
+import { PermissionButtons } from "./status/permission-buttons";
const HealthStatus = ({ className }: { className?: string }) => {
const { health } = useHealthCheck();
const { isOpen, open, close } = useStatusDialog();
const { settings, getDataDir } = useSettings();
const [localDataDir, setLocalDataDir] = useState("");
- const [permissions, setPermissions] = useState<PermissionsStatus | null>(
- null
- );
- const [isMacOS, setIsMacOS] = useState(false);
-
- useEffect(() => {
- const checkPermissions = async () => {
- try {
- const perms = await invoke<PermissionsStatus>("do_permissions_check", {
- initialCheck: true,
- });
-
- setPermissions({
- screenRecording: perms.screenRecording,
- microphone: perms.microphone,
- accessibility: perms.accessibility,
- });
- } catch (error) {
- console.error("Failed to check permissions:", error);
- }
- };
- checkPermissions();
- }, []);
-
- useEffect(() => {
- const checkPlatform = () => {
- const currentPlatform = platform();
- setIsMacOS(currentPlatform === "macos");
- };
- checkPlatform();
- }, []);
const handleOpenDataDir = async () => {
try {
@@ -159,64 +120,6 @@ const HealthStatus = ({ className }: { className?: string }) => {
}
};
- const handlePermissionButton = async (
- type: "screen" | "audio" | "accessibility"
- ) => {
- const toastId = toast({
- title: `checking ${type} permissions`,
- description: "please wait...",
- duration: Infinity,
- });
-
- try {
- const permissionType =
- type === "screen"
- ? "screenRecording"
- : type === "audio"
- ? "microphone"
- : "accessibility";
-
- await invoke("request_permission", {
- permission: permissionType,
- });
-
- const perms = await invoke<PermissionsStatus>("do_permissions_check", {
- initialCheck: false,
- });
-
- setPermissions({
- screenRecording: perms.screenRecording,
- microphone: perms.microphone,
- accessibility: perms.accessibility,
- });
-
- const granted =
- type === "screen"
- ? perms.screenRecording === "Granted"
- : type === "audio"
- ? perms.microphone === "Granted"
- : perms.accessibility === "Granted";
-
- toastId.update({
- id: toastId.id,
- title: granted ? "permission granted" : "permission check complete",
- description: granted
- ? `${type} permission was successfully granted`
- : `please try granting ${type} permission again if needed`,
- duration: 3000,
- });
- } catch (error) {
- console.error(`failed to handle ${type} permission:`, error);
- toastId.update({
- id: toastId.id,
- title: "error",
- description: `failed to handle ${type} permission`,
- variant: "destructive",
- duration: 3000,
- });
- }
- };
-
return (
<>
<Badge
@@ -274,27 +177,9 @@ const HealthStatus = ({ className }: { className?: string }) => {
{formatTimestamp(health?.last_frame_timestamp ?? null)}
</span>
</div>
- {isMacOS && (
- <div className="flex items-center gap-2">
- {permissions && (
- <span>
- {permissions.screenRecording ? (
- <Check className="h-4 w-4 text-green-500" />
- ) : (
- <X className="h-4 w-4 text-red-500" />
- )}
- </span>
- )}
- <Button
- variant="outline"
- className="w-[260px] text-sm justify-start"
- onClick={() => handlePermissionButton("screen")}
- >
- <Lock className="h-4 w-4 mr-2" />
- grant screen permission
- </Button>
- </div>
- )}
+ <div className="flex-shrink-0">
+ <PermissionButtons type="screen" settings={settings} />
+ </div>
</div>
{/* Audio Recording Status */}
@@ -323,28 +208,9 @@ const HealthStatus = ({ className }: { className?: string }) => {
: formatTimestamp(health?.last_audio_timestamp ?? null)}
</span>
</div>
- {isMacOS && (
- <div className="flex items-center gap-2">
- {permissions && (
- <span>
- {permissions.microphone ? (
- <Check className="h-4 w-4 text-green-500" />
- ) : (
- <X className="h-4 w-4 text-red-500" />
- )}
- </span>
- )}
- <Button
- variant="outline"
- className="w-[260px] text-sm justify-start"
- onClick={() => handlePermissionButton("audio")}
- disabled={settings.disableAudio}
- >
- <Lock className="h-4 w-4 mr-2" />
- grant audio permission
- </Button>
- </div>
- )}
+ <div className="flex-shrink-0">
+ <PermissionButtons type="audio" settings={settings} />
+ </div>
</div>
{/* UI Monitoring Status */}
@@ -366,27 +232,12 @@ const HealthStatus = ({ className }: { className?: string }) => {
)}
</span>
</div>
- {isMacOS && (
- <div className="flex items-center gap-2">
- {permissions && (
- <span>
- {permissions.accessibility ? (
- <Check className="h-4 w-4 text-green-500" />
- ) : (
- <X className="h-4 w-4 text-red-500" />
- )}
- </span>
- )}
- <Button
- variant="outline"
- className="w-[260px] text-sm justify-start"
- onClick={() => handlePermissionButton("accessibility")}
- >
- <Lock className="h-4 w-4 mr-2" />
- grant accessibility permission
- </Button>
- </div>
- )}
+ <div className="flex-shrink-0">
+ <PermissionButtons
+ type="accessibility"
+ settings={settings}
+ />
+ </div>
</div>
)}
</div>
diff --git a/screenpipe-app-tauri/components/status/permission-buttons.tsx b/screenpipe-app-tauri/components/status/permission-buttons.tsx
new file mode 100644
index 000000000..117635a96
--- /dev/null
+++ b/screenpipe-app-tauri/components/status/permission-buttons.tsx
@@ -0,0 +1,169 @@
+import React, { useEffect, useState } from "react";
+import { Button } from "@/components/ui/button";
+import { Check, Lock, Settings, X } from "lucide-react";
+import { toast } from "@/components/ui/use-toast";
+import { invoke } from "@tauri-apps/api/core";
+import { usePlatform } from "@/lib/hooks/use-platform";
+
+// You can add this to a types.ts file in your lib directory
+export enum OSPermissionStatus {
+ NotNeeded = "notNeeded",
+ Empty = "empty",
+ Granted = "granted",
+ Denied = "denied",
+}
+
+export interface OSPermissionsCheck {
+ screenRecording: OSPermissionStatus;
+ microphone: OSPermissionStatus;
+ accessibility: OSPermissionStatus;
+}
+
+interface PermissionButtonsProps {
+ settings: any;
+ type: "screen" | "audio" | "accessibility";
+}
+
+export const PermissionButtons: React.FC<PermissionButtonsProps> = ({
+ settings,
+ type,
+}) => {
+ const [permissions, setPermissions] = useState<OSPermissionsCheck | null>(
+ null
+ );
+ const { isMac: isMacOS } = usePlatform();
+
+ useEffect(() => {
+ const checkPermissions = async () => {
+ if (isMacOS) {
+ try {
+ const perms = await invoke<OSPermissionsCheck>(
+ "do_permissions_check",
+ {
+ initialCheck: true,
+ }
+ );
+ setPermissions(perms);
+ } catch (error) {
+ console.error("Failed to check permissions:", error);
+ }
+ }
+ };
+
+ // Poll permissions every 1 second
+ const intervalId = setInterval(() => {
+ checkPermissions();
+ }, 1000);
+
+ // Initial check
+ checkPermissions();
+
+ // Cleanup interval on unmount
+ return () => clearInterval(intervalId);
+ }, [isMacOS]);
+
+ const handlePermissionButton = async () => {
+ try {
+ const permissionType =
+ type === "screen"
+ ? "screenRecording"
+ : type === "audio"
+ ? "microphone"
+ : "accessibility";
+
+ await invoke("request_permission", {
+ permission: permissionType,
+ });
+
+ // Refresh permissions after request
+ const perms = await invoke<OSPermissionsCheck>("do_permissions_check", {
+ initialCheck: false,
+ });
+ setPermissions(perms);
+ } catch (error) {
+ console.error(`Failed to request ${type} permission:`, error);
+ toast({
+ title: "error",
+ description: `failed to request ${type} permission`,
+ variant: "destructive",
+ duration: 3000,
+ });
+ }
+ };
+
+ const handleOpenPermissionSettings = async () => {
+ try {
+ const permissionType =
+ type === "screen"
+ ? "screenRecording"
+ : type === "audio"
+ ? "microphone"
+ : "accessibility";
+
+ await invoke("open_permission_settings", {
+ permission: permissionType,
+ });
+ } catch (error) {
+ console.error(`failed to open ${type} permission settings:`, error);
+ toast({
+ title: "error",
+ description: `failed to open ${type} permission settings`,
+ variant: "destructive",
+ duration: 3000,
+ });
+ }
+ };
+
+ if (!isMacOS) return null;
+
+ const isPermitted = (status: OSPermissionStatus) =>
+ status === OSPermissionStatus.Granted ||
+ status === OSPermissionStatus.NotNeeded;
+
+ const permissionStatus =
+ type === "screen"
+ ? permissions?.screenRecording
+ : type === "audio"
+ ? permissions?.microphone
+ : permissions?.accessibility;
+
+ const isDisabled = type === "audio" && settings.disableAudio;
+
+ return (
+ <div className="flex items-center gap-2">
+ {permissions && (
+ <span>
+ {isPermitted(permissionStatus ?? OSPermissionStatus.Empty) ? (
+ <Check className="h-4 w-4 text-green-500" />
+ ) : (
+ <X className="h-4 w-4 text-red-500" />
+ )}
+ </span>
+ )}
+ <Button
+ variant="outline"
+ className="text-sm justify-center w-[220px]"
+ onClick={handlePermissionButton}
+ disabled={isDisabled}
+ >
+ allow{" "}
+ {type === "screen"
+ ? "screen"
+ : type === "audio"
+ ? "audio"
+ : "accessibility"}{" "}
+ access
+ </Button>
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8"
+ onClick={handleOpenPermissionSettings}
+ title={`Open ${type} settings`}
+ disabled={isDisabled}
+ >
+ <Settings className="h-4 w-4" />
+ </Button>
+ </div>
+ );
+};
diff --git a/screenpipe-app-tauri/lib/hooks/use-platform.tsx b/screenpipe-app-tauri/lib/hooks/use-platform.tsx
new file mode 100644
index 000000000..c5ce15538
--- /dev/null
+++ b/screenpipe-app-tauri/lib/hooks/use-platform.tsx
@@ -0,0 +1,69 @@
+import { getVersion } from "@tauri-apps/api/app";
+import { OsType, type } from "@tauri-apps/plugin-os";
+import { create } from "zustand";
+
+type PlatformState = {
+ platform: OsType | "unknown";
+ version: string;
+ isMac: boolean;
+ isWindows: boolean;
+ isLinux: boolean;
+ isLoading: boolean;
+ error: string | null;
+ init: () => Promise<void>;
+};
+
+const usePlatformStore = create<PlatformState>((set) => ({
+ platform: "unknown",
+ version: "",
+ isMac: false,
+ isWindows: false,
+ isLinux: false,
+ isLoading: true,
+ error: null,
+ init: async () => {
+ try {
+ // check if we're in a tauri environment
+ if (typeof type !== "function") {
+ set({
+ isLoading: false,
+ error: "not in tauri environment",
+ platform: "unknown",
+ });
+ return;
+ }
+
+ const platform = type();
+ const version = await getVersion();
+
+ set({
+ platform,
+ version,
+ isMac: platform === "macos",
+ isWindows: platform === "windows",
+ isLinux: platform === "linux",
+ isLoading: false,
+ });
+ } catch (error) {
+ set({
+ isLoading: false,
+ error: error instanceof Error ? error.message : "unknown error",
+ });
+ }
+ },
+}));
+
+// initialize the store on first import
+let initialized = false;
+
+export function usePlatform() {
+ const store = usePlatformStore();
+
+ // initialize only once
+ if (!initialized) {
+ initialized = true;
+ store.init();
+ }
+
+ return store;
+}
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.lock b/screenpipe-app-tauri/src-tauri/Cargo.lock
index 0a6b4912b..81ae3dd10 100755
--- a/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -5199,8 +5199,8 @@ dependencies = [
[[package]]
name = "scap"
-version = "0.0.7"
-source = "git+https://github.com/CapSoftware/scap?rev=58d4410bf52f#58d4410bf52fb8033be99dcc62a27369a4cbaf32"
+version = "0.0.8"
+source = "git+https://github.com/CapSoftware/scap?rev=92cabc5#92cabc5b4628a238b626a085b04cc0be0746cd1e"
dependencies = [
"cocoa 0.25.0",
"core-graphics-helmer-fork",
@@ -5289,7 +5289,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "0.37.5"
+version = "0.37.6"
dependencies = [
"anyhow",
"async-stream",
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.toml
index d6da2cd2c..c9bb2272f 100644
--- a/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "0.37.5"
+version = "0.37.6"
description = ""
authors = ["you"]
license = ""
@@ -98,7 +98,7 @@ cocoa = "0.26.0"
objc = "0.2.7"
base64 = "0.22.1"
# bunch of hack for permissions
-scap = { git = "https://github.com/CapSoftware/scap", rev = "58d4410bf52f" }
+scap = { git = "https://github.com/CapSoftware/scap", rev = "92cabc5" }
nokhwa-bindings-macos = { git = "https://github.com/CapSoftware/nokhwa", rev = "0d3d1f30a78b" }
tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" }