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

add toggle to screenpipe overlay shortcut (#828)

Ezra Ellette5ccf5ecd22a3
diff --git a/screenpipe-app-tauri/app/page.tsx b/screenpipe-app-tauri/app/page.tsx
index 96a46432a..ff986803f 100644
--- a/screenpipe-app-tauri/app/page.tsx
+++ b/screenpipe-app-tauri/app/page.tsx
@@ -57,8 +57,9 @@ export default function Home() {
useEffect(() => {
registerShortcuts({
showScreenpipeShortcut: settings.showScreenpipeShortcut,
+ disabledShortcuts: settings.disabledShortcuts,
});
- }, [settings.showScreenpipeShortcut]);
+ }, [settings.showScreenpipeShortcut, settings.disabledShortcuts]);
useEffect(() => {
if (settings.userId) {
diff --git a/screenpipe-app-tauri/components/settings.tsx b/screenpipe-app-tauri/components/settings.tsx
index 9bc73ac89..30ac4a130 100644
--- a/screenpipe-app-tauri/components/settings.tsx
+++ b/screenpipe-app-tauri/components/settings.tsx
@@ -11,7 +11,11 @@ import {
DialogTrigger,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
-import { useSettings, AIProviderType } from "@/lib/hooks/use-settings";
+import {
+ useSettings,
+ AIProviderType,
+ Shortcut,
+} from "@/lib/hooks/use-settings";
import {
Tooltip,
TooltipContent,
@@ -76,6 +80,10 @@ export function Settings({ className }: { className?: string }) {
"idle" | "running" | "error"
>("idle");
+ const [disabledShortcuts, setDisabledShortcuts] = useState<Shortcut[]>(
+ settings.disabledShortcuts
+ );
+
useEffect(() => {
setCurrentShortcut(settings.showScreenpipeShortcut);
@@ -123,6 +131,7 @@ export function Settings({ className }: { className?: string }) {
updateSettings({ showScreenpipeShortcut: newShortcut });
registerShortcuts({
showScreenpipeShortcut: newShortcut,
+ disabledShortcuts,
});
setCurrentShortcut(newShortcut);
@@ -475,6 +484,32 @@ export function Settings({ className }: { className?: string }) {
// Use the useInterval hook to periodically check the status
useInterval(checkEmbeddedAIStatus, 10000); // Check every 10 seconds
+
+ const handleShortcutToggle = (checked: boolean) => {
+ console.log("handleShortcutToggle", checked);
+ let newDisabledShortcuts = [...localSettings.disabledShortcuts];
+ if (!checked) {
+ newDisabledShortcuts.push(Shortcut.SHOW_SCREENPIPE);
+ } else {
+ newDisabledShortcuts = newDisabledShortcuts.filter(
+ (shortcut) => shortcut !== Shortcut.SHOW_SCREENPIPE
+ );
+ }
+
+ setLocalSettings({
+ ...localSettings,
+ disabledShortcuts: newDisabledShortcuts,
+ });
+ updateSettings({
+ disabledShortcuts: newDisabledShortcuts,
+ });
+
+ registerShortcuts({
+ showScreenpipeShortcut: settings.showScreenpipeShortcut,
+ disabledShortcuts: newDisabledShortcuts,
+ });
+ };
+
useEffect(() => {
const handleSettingsUpdate = () => {
debouncedFetchHealth();
@@ -487,6 +522,7 @@ export function Settings({ className }: { className?: string }) {
};
}, [debouncedFetchHealth]);
+
return (
<Dialog
onOpenChange={(open) => {
@@ -957,46 +993,71 @@ export function Settings({ className }: { className?: string }) {
<CardTitle className="text-center">shortcuts</CardTitle>
</CardHeader>
<CardContent className="flex flex-col items-center">
- <h2 className="text-lg font-semibold mb-4">
- set shortcut for screenpipe overlay
- </h2>
- <p className="text-sm text-muted-foreground mb-4">
- use the following options to set a keyboard shortcut for showing
- the screenpipe overlay.
- </p>
- <div className="flex items-center gap-2 mb-4">
- {["ctrl", "alt", "shift", "super"].map((modifier) => (
- <label key={modifier} className="flex items-center">
- <input
- type="checkbox"
- checked={selectedModifiers.includes(modifier)}
- onChange={() => toggleModifier(modifier)}
- />
- <span className="ml-2">
- {parseKeyboardShortcut(modifier)}
- </span>
- </label>
- ))}
- <input
- type="text"
- value={nonModifierKey}
- onChange={handleNonModifierKeyChange}
- placeholder="enter key"
- className="border p-1"
+ <div
+ className={
+ settings.disabledShortcuts.includes(Shortcut.SHOW_SCREENPIPE)
+ ? "opacity-50 pointer-events-none"
+ : ""
+ }
+ >
+ <h2 className="text-lg font-semibold mb-4">
+ set shortcut for screenpipe overlay
+ </h2>
+ <p className="text-sm text-muted-foreground mb-4">
+ use the following options to set a keyboard shortcut for
+ showing the screenpipe overlay.
+ </p>
+ <div className="flex items-center gap-2 mb-4">
+ {["ctrl", "alt", "shift", "super"].map((modifier) => (
+ <label key={modifier} className="flex items-center">
+ <input
+ type="checkbox"
+ checked={selectedModifiers.includes(modifier)}
+ onChange={() => toggleModifier(modifier)}
+ />
+ <span className="ml-2">
+ {parseKeyboardShortcut(modifier)}
+ </span>
+ </label>
+ ))}
+ <input
+ type="text"
+ value={nonModifierKey}
+ onChange={handleNonModifierKeyChange}
+ placeholder="enter key"
+ className="border p-1"
+ />
+ <button
+ onClick={handleSetShortcut}
+ className={`btn btn-primary ${
+ !isShortcutChanged ? "opacity-50 cursor-not-allowed" : ""
+ }`}
+ disabled={!isShortcutChanged}
+ >
+ set shortcut
+ </button>
+ </div>
+ <p className="mt-2 text-sm text-muted-foreground text-center">
+ current shortcut: {parseKeyboardShortcut(currentShortcut)}
+ </p>
+ </div>
+ <div className="w-full flex justify-center gap-2 items-center">
+ <Label htmlFor="shortcutEnabled" className="mt-2 text-sm">
+ {settings.disabledShortcuts.includes(Shortcut.SHOW_SCREENPIPE)
+ ? "enable shortcut"
+ : "disable shortcut"}
+ </Label>
+ <Switch
+ id="shortcutEnabled"
+ checked={
+ !settings.disabledShortcuts.includes(
+ Shortcut.SHOW_SCREENPIPE
+ )
+ }
+ onCheckedChange={handleShortcutToggle}
+ className="mt-2"
/>
- <button
- onClick={handleSetShortcut}
- className={`btn btn-primary ${
- !isShortcutChanged ? "opacity-50 cursor-not-allowed" : ""
- }`}
- disabled={!isShortcutChanged}
- >
- set shortcut
- </button>
</div>
- <p className="mt-2 text-sm text-muted-foreground text-center">
- current shortcut: {parseKeyboardShortcut(currentShortcut)}
- </p>
</CardContent>
</Card>
</div>
diff --git a/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/screenpipe-app-tauri/lib/hooks/use-settings.tsx
index 3c1702827..4a9691e9b 100644
--- a/screenpipe-app-tauri/lib/hooks/use-settings.tsx
+++ b/screenpipe-app-tauri/lib/hooks/use-settings.tsx
@@ -21,6 +21,10 @@ export type EmbeddedLLMConfig = {
port: number;
};
+export enum Shortcut {
+ SHOW_SCREENPIPE = "show_screenpipe",
+}
+
export interface Settings {
openaiApiKey: string;
deepgramApiKey: string;
@@ -57,6 +61,7 @@ export interface Settings {
enableFrameCache: boolean; // Add this line
enableUiMonitoring: boolean; // Add this line
platform: string; // Add this line
+ disabledShortcuts: Shortcut[];
}
const defaultSettings: Settings = {
@@ -105,6 +110,7 @@ const defaultSettings: Settings = {
enableFrameCache: true, // Add this line
enableUiMonitoring: false, // Change from true to false
platform: "unknown", // Add this line
+ disabledShortcuts: [],
};
let store: Awaited<ReturnType<typeof createStore>> | null = null;
@@ -148,8 +154,8 @@ export function useSettings() {
currentPlatform === "macos"
? "apple-native"
: currentPlatform === "windows"
- ? "windows-native"
- : "tesseract";
+ ? "windows-native"
+ : "tesseract";
console.log("loading settings", store);
// no need to call load() as it's done automatically
@@ -244,29 +250,29 @@ export function useSettings() {
const defaultIgnoredWindows =
currentPlatform === "macos"
? [
- ...ignoredWindowsInAllOS,
- ".env",
- "Item-0",
- "App Icon Window",
- "Battery",
- "Shortcuts",
- "WiFi",
- "BentoBox",
- "Clock",
- "Dock",
- "DeepL",
- "Control Center",
- ]
+ ...ignoredWindowsInAllOS,
+ ".env",
+ "Item-0",
+ "App Icon Window",
+ "Battery",
+ "Shortcuts",
+ "WiFi",
+ "BentoBox",
+ "Clock",
+ "Dock",
+ "DeepL",
+ "Control Center",
+ ]
: currentPlatform === "windows"
- ? [
+ ? [
...ignoredWindowsInAllOS,
"Nvidia",
"Control Panel",
"System Properties",
]
- : currentPlatform === "linux"
- ? [...ignoredWindowsInAllOS, "Info center", "Discover", "Parted"]
- : [];
+ : currentPlatform === "linux"
+ ? [...ignoredWindowsInAllOS, "Info center", "Discover", "Parted"]
+ : [];
const savedIgnoredWindows = await store!.get<string[]>(
"ignoredWindows"
@@ -298,6 +304,9 @@ export function useSettings() {
const savedEnableUiMonitoring =
(await store!.get<boolean>("enableUiMonitoring")) || false;
+ const savedDisabledShortcuts =
+ (await store!.get<Shortcut[]>("disabledShortcuts")) || [];
+
setSettings({
openaiApiKey: savedKey,
deepgramApiKey: savedDeepgramKey,
@@ -334,6 +343,7 @@ export function useSettings() {
enableFrameCache: savedEnableFrameCache,
enableUiMonitoring: savedEnableUiMonitoring,
platform: currentPlatform,
+ disabledShortcuts: savedDisabledShortcuts,
});
} catch (error) {
console.error("failed to load settings:", error);
@@ -375,12 +385,17 @@ export function useSettings() {
const getDataDir = async () => {
const homeDirPath = await homeDir();
- if (settings.dataDir !== "default" && settings.dataDir && settings.dataDir !== "") return settings.dataDir;
+ if (
+ settings.dataDir !== "default" &&
+ settings.dataDir &&
+ settings.dataDir !== ""
+ )
+ return settings.dataDir;
return platform() === "macos" || platform() === "linux"
? `${homeDirPath}/.screenpipe`
: `${homeDirPath}\\.screenpipe`;
- }
+ };
return { settings, updateSettings, resetSetting, getDataDir };
}
diff --git a/screenpipe-app-tauri/lib/shortcuts.ts b/screenpipe-app-tauri/lib/shortcuts.ts
index afa9c427c..17434ab7d 100644
--- a/screenpipe-app-tauri/lib/shortcuts.ts
+++ b/screenpipe-app-tauri/lib/shortcuts.ts
@@ -1,11 +1,15 @@
import { invoke } from "@tauri-apps/api/core";
+import { Shortcut } from "./hooks/use-settings";
export async function registerShortcuts({
showScreenpipeShortcut,
+ disabledShortcuts,
}: {
showScreenpipeShortcut: string;
+ disabledShortcuts: Shortcut[];
}) {
invoke("update_show_screenpipe_shortcut", {
new_shortcut: showScreenpipeShortcut,
+ enabled: !disabledShortcuts.includes(Shortcut.SHOW_SCREENPIPE),
});
}
diff --git a/screenpipe-app-tauri/src-tauri/src/commands.rs b/screenpipe-app-tauri/src-tauri/src/commands.rs
index 8421c384f..917f23aea 100644
--- a/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -139,6 +139,7 @@ const DEFAULT_SHORTCUT: &str = "Super+Alt+S";
pub fn update_show_screenpipe_shortcut(
app_handle: tauri::AppHandle<tauri::Wry>,
new_shortcut: String,
+ enabled: bool,
) -> Result<(), String> {
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
@@ -168,6 +169,12 @@ pub fn update_show_screenpipe_shortcut(
}
};
+ if !enabled {
+ app_handle.global_shortcut().unregister(show_window_shortcut);
+
+ return Ok(());
+ }
+
// Register the new shortcut
if let Err(e) = app_handle.global_shortcut().on_shortcut(
show_window_shortcut,