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

Pipe shortcuts (#1077)

neo7737a06d53cf0ab
diff --git a/screenpipe-app-tauri/app/page.tsx b/screenpipe-app-tauri/app/page.tsx
index 731bb8e96..533d94c96 100644
--- a/screenpipe-app-tauri/app/page.tsx
+++ b/screenpipe-app-tauri/app/page.tsx
@@ -30,6 +30,7 @@ import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { useProfiles } from "@/lib/hooks/use-profiles";
import { relaunch } from "@tauri-apps/plugin-process";
+import { PipeApi } from "@/lib/api";
export default function Home() {
const { settings } = useSettings();
@@ -76,6 +77,21 @@ export default function Home() {
await new Promise((resolve) => setTimeout(resolve, 1000));
relaunch();
}),
+
+ listen<string>('open-pipe', async (event) => {
+ const pipeId = event.payload;
+
+ const pipeApi = new PipeApi();
+ const pipeList = await pipeApi.listPipes();
+ const pipe = pipeList.find(p => p.id === pipeId);
+ if (pipe) {
+ await invoke("open_pipe_window", {
+ port: pipe.port,
+ title: pipe.id,
+ });
+ }
+ })
+
]);
return () => {
diff --git a/screenpipe-app-tauri/components/settings/shortcut-row.tsx b/screenpipe-app-tauri/components/settings/shortcut-row.tsx
new file mode 100644
index 000000000..4cf99a51e
--- /dev/null
+++ b/screenpipe-app-tauri/components/settings/shortcut-row.tsx
@@ -0,0 +1,269 @@
+import React, { useEffect, useState } from "react";
+import { Settings, Shortcut, useSettings } from "@/lib/hooks/use-settings";
+import { useProfiles } from "@/lib/hooks/use-profiles";
+import { parseKeyboardShortcut } from "@/lib/utils";
+import { Switch } from "@/components/ui/switch";
+import { toast } from "@/components/ui/use-toast";
+import { cn } from "@/lib/utils";
+import { Pencil } from "lucide-react";
+import { invoke } from "@tauri-apps/api/core";
+import hotkeys from "hotkeys-js";
+
+interface ShortcutRowProps {
+ shortcut: string;
+ title: string;
+ description: string;
+ type: "global" | "profile" | "pipe";
+ value?: string;
+}
+
+enum ShortcutState {
+ ENABLED = "enabled",
+ DISABLED = "disabled",
+ UNASSIGNED = "unassigned",
+}
+
+const ShortcutRow = ({
+ shortcut,
+ title,
+ description,
+ type,
+ value,
+}: ShortcutRowProps) => {
+ const [isRecording, setIsRecording] = useState(false);
+ const { settings, updateSettings } = useSettings();
+ const { profileShortcuts, updateProfileShortcut } = useProfiles();
+
+ useEffect(() => {
+ if (!isRecording) return;
+
+ const handleKeyDown = (event: KeyboardEvent) => {
+ event.preventDefault();
+
+ const MODIFIER_KEYS = ["SUPER", "CTRL", "ALT", "SHIFT"] as const;
+ const KEY_CODE_MAP: Record<number, string> = {
+ 91: "SUPER",
+ 93: "SUPER",
+ 16: "SHIFT",
+ 17: "CTRL",
+ 18: "ALT",
+ };
+
+ const pressedKeys = hotkeys
+ .getPressedKeyCodes()
+ .map((code) => KEY_CODE_MAP[code] || String.fromCharCode(code))
+ .filter((value, index, self) => self.indexOf(value) === index);
+
+ const modifiers = pressedKeys.filter((k) =>
+ MODIFIER_KEYS.includes(k as any)
+ );
+ const normalKeys = pressedKeys.filter(
+ (k) => !MODIFIER_KEYS.includes(k as any)
+ );
+ const finalKeys = [...modifiers, ...normalKeys];
+
+ if (normalKeys.length > 0) {
+ handleEnableShortcut(finalKeys.join("+"));
+ setIsRecording(false);
+ }
+ };
+
+ hotkeys.filter = () => true;
+ hotkeys("*", handleKeyDown);
+
+ return () => {
+ setIsRecording(false);
+ hotkeys.unbind("*");
+ hotkeys.filter = (event) => {
+ const target = (event.target || event.srcElement) as any;
+ return !(
+ target.isContentEditable ||
+ target.tagName === "INPUT" ||
+ target.tagName === "TEXTAREA"
+ );
+ };
+ };
+ }, [isRecording]);
+
+ const syncShortcuts = async (updatedShortcuts: {
+ showScreenpipeShortcut: string;
+ startRecordingShortcut: string;
+ stopRecordingShortcut: string;
+ profileShortcuts: Record<string, string>;
+ pipeShortcuts: Record<string, string>;
+ }) => {
+ console.log("syncing shortcuts:", {
+ showShortcut: updatedShortcuts.showScreenpipeShortcut,
+ startShortcut: updatedShortcuts.startRecordingShortcut,
+ stopShortcut: updatedShortcuts.stopRecordingShortcut,
+ profileShortcuts: updatedShortcuts.profileShortcuts,
+ pipeShortcuts: updatedShortcuts.pipeShortcuts,
+ });
+ // wait 1 second
+ await new Promise((resolve) => setTimeout(resolve, 1000));
+ await invoke("update_global_shortcuts", {
+ showShortcut: updatedShortcuts.showScreenpipeShortcut,
+ startShortcut: updatedShortcuts.startRecordingShortcut,
+ stopShortcut: updatedShortcuts.stopRecordingShortcut,
+ profileShortcuts: updatedShortcuts.profileShortcuts,
+ pipeShortcuts: updatedShortcuts.pipeShortcuts,
+ });
+
+ return true;
+ };
+
+ const handleEnableShortcut = async (keys: string) => {
+ try {
+ toast({
+ title: "shortcut enabled",
+ description: `${shortcut.replace(/_/g, " ")} enabled`,
+ });
+
+ // Remove from disabled shortcuts if it exists
+ updateSettings({
+ disabledShortcuts: settings.disabledShortcuts.filter(
+ (s) => s !== shortcut
+ ),
+ });
+
+ switch (type) {
+ case "global":
+ updateSettings({ [shortcut]: keys });
+ await syncShortcuts({
+ ...settings,
+ [shortcut]: keys,
+ profileShortcuts,
+ pipeShortcuts: settings.pipeShortcuts,
+ });
+ break;
+ case "profile":
+ const profileId = shortcut.replace("profile_", "");
+ updateProfileShortcut({
+ profile: profileId,
+ shortcut: keys,
+ });
+ await syncShortcuts({
+ ...settings,
+ profileShortcuts: {
+ ...profileShortcuts,
+ [profileId]: keys,
+ },
+ pipeShortcuts: settings.pipeShortcuts,
+ });
+ break;
+ case "pipe":
+ const pipeId = shortcut.replace("pipe_", "");
+ updateSettings({
+ pipeShortcuts: {
+ ...settings.pipeShortcuts,
+ [pipeId]: keys,
+ },
+ });
+ await syncShortcuts({
+ ...settings,
+ profileShortcuts,
+ pipeShortcuts: {
+ ...settings.pipeShortcuts,
+ [pipeId]: keys,
+ },
+ });
+ break;
+ }
+ } catch (error) {
+ toast({
+ title: "error updating shortcut",
+ description:
+ "failed to register shortcut. please try a different combination.",
+ variant: "destructive",
+ });
+ }
+ };
+
+ const handleDisableShortcut = async () => {
+ toast({
+ title: "shortcut disabled",
+ description: `${shortcut.replace(/_/g, " ")} disabled`,
+ });
+ updateSettings({
+ disabledShortcuts: Array.from(
+ new Set([...settings.disabledShortcuts, shortcut as Shortcut])
+ ),
+ });
+
+ await syncShortcuts({
+ ...settings,
+ profileShortcuts,
+ pipeShortcuts: settings.pipeShortcuts,
+ });
+ };
+
+ const isValueEmpty = (v: string | undefined): boolean =>
+ !v || v.trim() === "";
+
+ const currentKeys = isValueEmpty(value)
+ ? ["Unassigned"]
+ : parseKeyboardShortcut(value || "").split("+");
+
+ const getShortcutState = (): ShortcutState => {
+ if (isValueEmpty(value)) return ShortcutState.UNASSIGNED;
+ return settings.disabledShortcuts.includes(shortcut as Shortcut)
+ ? ShortcutState.DISABLED
+ : ShortcutState.ENABLED;
+ };
+
+ return (
+ <div className="flex items-center justify-between">
+ <div className="space-y-1">
+ <h4 className="font-medium">{title}</h4>
+ <p className="text-sm text-muted-foreground">{description}</p>
+ </div>
+ <div className="flex items-center gap-4">
+ <button
+ onClick={() => setIsRecording(true)}
+ className={cn(
+ "relative min-w-[140px] rounded-md border px-3 py-2 text-sm",
+ "bg-muted/50 hover:bg-muted/70 transition-colors",
+ "focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-ring",
+ isRecording && "border-primary",
+ !value && "text-muted-foreground"
+ )}
+ >
+ {isRecording ? (
+ <span className="animate-pulse">recording...</span>
+ ) : (
+ <span className="flex items-center justify-between gap-2">
+ {currentKeys.map((key, i) => (
+ <kbd
+ key={i}
+ className={cn(
+ "px-1 rounded",
+ value ? "bg-background/50" : "bg-transparent"
+ )}
+ >
+ {key}
+ </kbd>
+ ))}
+ <Pencil className="h-3 w-3 opacity-50" />
+ </span>
+ )}
+ </button>
+
+ <Switch
+ checked={getShortcutState() === ShortcutState.ENABLED}
+ disabled={getShortcutState() === ShortcutState.UNASSIGNED}
+ onCheckedChange={async (checked) => {
+ if (checked && value) {
+ console.log("re-enabling shortcut", value);
+ await handleEnableShortcut(value);
+ } else {
+ console.log("disabling shortcut", shortcut);
+ await handleDisableShortcut();
+ }
+ }}
+ />
+ </div>
+ </div>
+ );
+};
+
+export default ShortcutRow;
diff --git a/screenpipe-app-tauri/components/settings/shortcut-section.tsx b/screenpipe-app-tauri/components/settings/shortcut-section.tsx
index 166259d9b..744fca73f 100644
--- a/screenpipe-app-tauri/components/settings/shortcut-section.tsx
+++ b/screenpipe-app-tauri/components/settings/shortcut-section.tsx
@@ -1,253 +1,26 @@
import React, { useEffect, useState } from "react";
-import { Settings, Shortcut, useSettings } from "@/lib/hooks/use-settings";
+import { useSettings } from "@/lib/hooks/use-settings";
import { useProfiles } from "@/lib/hooks/use-profiles";
-import { parseKeyboardShortcut } from "@/lib/utils";
-import { Switch } from "@/components/ui/switch";
-import { toast } from "@/components/ui/use-toast";
-import { cn } from "@/lib/utils";
-import { Pencil } from "lucide-react";
-import { invoke } from "@tauri-apps/api/core";
-import hotkeys from "hotkeys-js";
-
-interface ShortcutRowProps {
- shortcut: string;
- title: string;
- description: string;
-}
-
-interface ShortcutState {
- isRecording: boolean;
- pressedKeys: string[];
-}
+import { PipeApi } from "@/lib/api";
+import ShortcutRow from "./shortcut-row";
const ShortcutSection = () => {
- const { settings, updateSettings } = useSettings();
- const {
- profiles,
- shortcuts,
- updateShortcut: updateProfileShortcut,
- } = useProfiles();
-
- const [shortcutStates, setShortcutStates] = useState<
- Record<string, ShortcutState>
- >(() => ({
- showScreenpipeShortcut: { isRecording: false, pressedKeys: [] },
- startRecordingShortcut: { isRecording: false, pressedKeys: [] },
- stopRecordingShortcut: { isRecording: false, pressedKeys: [] },
- ...Object.fromEntries(
- profiles.map((profile) => [
- `profile_${profile}`,
- { isRecording: false, pressedKeys: [] },
- ])
- ),
- }));
-
- const updateShortcut = async (shortcutId: string, keys: string) => {
- try {
- let updatedSettings = { ...settings };
- if (shortcutId.startsWith("profile_")) {
- const profileName = shortcutId.replace("profile_", "");
- updateProfileShortcut({ profile: profileName, shortcut: keys });
- } else {
- const updates: Partial<Settings> = {
- [shortcutId]: keys,
- };
- updatedSettings = { ...settings, ...updates };
- updateSettings(updates);
- }
-
- // wait 2 seconds to make sure store has synced to disk
- await new Promise((resolve) => setTimeout(resolve, 2000));
- await invoke("update_global_shortcuts", {
- showShortcut: updatedSettings.showScreenpipeShortcut,
- startShortcut: updatedSettings.startRecordingShortcut,
- stopShortcut: updatedSettings.stopRecordingShortcut,
- profileShortcuts: shortcuts,
- });
-
- return true;
- } catch (error) {
- console.error("failed to update shortcut:", error);
- return false;
- }
- };
-
- const processKeyboardEvent = (event: KeyboardEvent, shortcutKey: string) => {
- event.preventDefault();
-
- const MODIFIER_KEYS = ["SUPER", "CTRL", "ALT", "SHIFT"] as const;
- const KEY_CODE_MAP: Record<number, string> = {
- 91: "SUPER", // Command/Windows key
- 93: "SUPER", // Right Command/Windows
- 16: "SHIFT",
- 17: "CTRL",
- 18: "ALT",
- };
-
- const pressedKeys = hotkeys
- .getPressedKeyCodes()
- .map((code) => KEY_CODE_MAP[code] || String.fromCharCode(code))
- .filter((value, index, self) => self.indexOf(value) === index);
-
- const modifiers = pressedKeys.filter((k) =>
- MODIFIER_KEYS.includes(k as any)
- );
- const normalKeys = pressedKeys.filter(
- (k) => !MODIFIER_KEYS.includes(k as any)
- );
- const finalKeys = [...modifiers, ...normalKeys];
-
- setShortcutStates((prev) => ({
- ...prev,
- [shortcutKey]: {
- ...prev[shortcutKey],
- pressedKeys: finalKeys,
- },
- }));
-
- if (normalKeys.length > 0) {
- handleShortcutUpdate(shortcutKey, finalKeys.join("+"));
- }
- };
+ const [pipes, setPipes] = useState<{ id: string; source: string }[]>([]);
+ const { settings } = useSettings();
+ const { profiles, profileShortcuts } = useProfiles();
useEffect(() => {
- const activeShortcut = Object.entries(shortcutStates).find(
- ([_, state]) => state.isRecording
- );
- if (!activeShortcut) return;
-
- hotkeys.filter = () => true;
- hotkeys("*", (event) => processKeyboardEvent(event, activeShortcut[0]));
-
- return () => hotkeys.unbind("*");
- }, [shortcutStates]);
-
- const ShortcutRow = ({ shortcut, title, description }: ShortcutRowProps) => {
- const state = shortcutStates[shortcut] || {
- isRecording: false,
- pressedKeys: [],
+ const loadPipes = async () => {
+ try {
+ const pipeApi = new PipeApi();
+ const pipeList = await pipeApi.listPipes();
+ setPipes(pipeList.map((p) => ({ id: p.id, source: p.source })));
+ } catch (error) {
+ console.error("failed to load pipes:", error);
+ }
};
- const currentValue = getShortcutValue(shortcut, settings, shortcuts);
-
- const currentKeys = state.isRecording
- ? state.pressedKeys
- : currentValue
- ? parseKeyboardShortcut(currentValue).split("+")
- : ["Unassigned"];
-
- return (
- <div className="flex items-center justify-between">
- <div className="space-y-1">
- <h4 className="font-medium">{title}</h4>
- <p className="text-sm text-muted-foreground">{description}</p>
- </div>
- <div className="flex items-center gap-4">
- <button
- onClick={() =>
- setShortcutStates((prev) => ({
- ...prev,
- [shortcut]: { ...prev[shortcut], isRecording: true },
- }))
- }
- className={cn(
- "relative min-w-[140px] rounded-md border px-3 py-2 text-sm",
- "bg-muted/50 hover:bg-muted/70 transition-colors",
- "focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-ring",
- state.isRecording && "border-primary",
- !currentValue && "text-muted-foreground"
- )}
- >
- {state.isRecording ? (
- <span className="animate-pulse">recording...</span>
- ) : (
- <span className="flex items-center justify-between gap-2">
- {currentKeys.map((key, i) => (
- <kbd
- key={i}
- className={cn(
- "px-1 rounded",
- currentValue ? "bg-background/50" : "bg-transparent"
- )}
- >
- {key}
- </kbd>
- ))}
- <Pencil className="h-3 w-3 opacity-50" />
- </span>
- )}
- </button>
-
- <Switch
- checked={!!currentValue}
- disabled={typeof currentValue === "undefined"}
- onCheckedChange={async (checked) => {
- if (!checked) {
- handleShortcutUpdate(shortcut, "", true);
- }
- }}
- />
- </div>
- </div>
- );
- };
-
- const handleShortcutUpdate = async (
- shortcut: string,
- keys: string,
- disable?: boolean
- ) => {
- const success = await updateShortcut(shortcut, keys);
- if (!success) {
- toast({
- title: "error updating shortcut",
- description:
- "failed to register shortcut. please try a different combination.",
- variant: "destructive",
- });
- return;
- }
-
- if (disable) {
- updateSettings({
- disabledShortcuts: [
- ...settings.disabledShortcuts,
- shortcut as Shortcut,
- ],
- });
- toast({
- title: "shortcut disabled",
- description: `${shortcut.replace(/_/g, " ")} disabled`,
- });
- return;
- }
-
- toast({
- title: "shortcut updated",
- description: `${shortcut.replace(
- /_/g,
- " "
- )} set to: ${parseKeyboardShortcut(keys)}`,
- });
-
- // Reset recording state
- setShortcutStates((prev) => ({
- ...prev,
- [shortcut]: { isRecording: false, pressedKeys: [] },
- }));
- };
-
- // Helper to get shortcut value
- const getShortcutValue = (
- shortcut: string,
- settings: Settings,
- profileShortcuts: Record<string, string>
- ): string | undefined => {
- if (shortcut.startsWith("profile_")) {
- const profileName = shortcut.replace("profile_", "");
- return profileShortcuts[profileName];
- }
- return settings[shortcut as keyof Settings] as string;
- };
+ loadPipes();
+ }, []);
return (
<div className="w-full space-y-6 py-4">
@@ -255,21 +28,27 @@ const ShortcutSection = () => {
<div className="space-y-6">
<ShortcutRow
- shortcut={"showScreenpipeShortcut"}
+ type="global"
+ shortcut="showScreenpipeShortcut"
title="toggle screenpipe overlay"
description="global shortcut to show/hide the main interface"
+ value={settings.showScreenpipeShortcut}
/>
<ShortcutRow
- shortcut={"startRecordingShortcut"}
+ type="global"
+ shortcut="startRecordingShortcut"
title="start recording"
description="global shortcut to start screen recording"
+ value={settings.startRecordingShortcut}
/>
<ShortcutRow
- shortcut={"stopRecordingShortcut"}
+ type="global"
+ shortcut="stopRecordingShortcut"
title="stop recording"
description="global shortcut to stop screen recording"
+ value={settings.stopRecordingShortcut}
/>
{profiles.length > 1 && (
@@ -284,9 +63,33 @@ const ShortcutSection = () => {
{profiles.map((profile) => (
<ShortcutRow
key={profile}
+ type="profile"
shortcut={`profile_${profile}`}
title={`switch to ${profile}`}
description={`activate ${profile} profile`}
+ value={profileShortcuts[profile]}
+ />
+ ))}
+ </>
+ )}
+
+ {pipes.length > 0 && (
+ <>
+ <div className="mt-8 mb-4">
+ <h2 className="text-lg font-semibold">pipe shortcuts</h2>
+ <p className="text-sm text-muted-foreground">
+ assign shortcuts to quickly trigger installed pipes
+ </p>
+ </div>
+
+ {pipes.map((pipe) => (
+ <ShortcutRow
+ key={pipe.id}
+ type="pipe"
+ shortcut={`pipe_${pipe.id}`}
+ title={`trigger ${pipe.id} pipe`}
+ description={`run pipe ${pipe.id}`}
+ value={settings.pipeShortcuts[pipe.id]}
/>
))}
</>
diff --git a/screenpipe-app-tauri/lib/api/index.ts b/screenpipe-app-tauri/lib/api/index.ts
new file mode 100644
index 000000000..b8f1aa8bd
--- /dev/null
+++ b/screenpipe-app-tauri/lib/api/index.ts
@@ -0,0 +1,53 @@
+interface PipeCron {
+ path: string;
+ schedule: string;
+}
+
+interface PipeConfig {
+ crons: PipeCron[];
+ is_nextjs: boolean;
+ source: string;
+}
+
+interface Pipe {
+ config: PipeConfig;
+ enabled: boolean;
+ id: string;
+ port: number | null;
+ source: string;
+}
+
+interface PipeListResponse {
+ data: Pipe[];
+ success: boolean;
+}
+
+interface PipeShortcut {
+ pipeId: string;
+ shortcut: string;
+}
+
+export class PipeApi {
+ private baseUrl: string;
+
+ constructor(baseUrl: string = 'http://localhost:3030') {
+ this.baseUrl = baseUrl;
+ }
+
+ async listPipes(): Promise<Pipe[]> {
+ try {
+ const response = await fetch(`${this.baseUrl}/pipes/list`);
+ if (!response.ok) {
+ throw new Error(`failed to fetch pipes: ${response.statusText}`);
+ }
+ const data: PipeListResponse = await response.json();
+ if (!data.success) {
+ throw new Error('failed to list pipes: api returned success: false');
+ }
+ return data.data;
+ } catch (error) {
+ console.error('error listing pipes:', error);
+ throw error;
+ }
+ }
+}
diff --git a/screenpipe-app-tauri/lib/hooks/use-profiles.tsx b/screenpipe-app-tauri/lib/hooks/use-profiles.tsx
index c482cd053..524ff64ec 100644
--- a/screenpipe-app-tauri/lib/hooks/use-profiles.tsx
+++ b/screenpipe-app-tauri/lib/hooks/use-profiles.tsx
@@ -227,10 +227,10 @@ export const useProfiles = () => {
return {
profiles,
activeProfile,
- shortcuts,
+ profileShortcuts: shortcuts,
setActiveProfile,
createProfile,
deleteProfile,
- updateShortcut,
+ updateProfileShortcut: updateShortcut,
};
};
diff --git a/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/screenpipe-app-tauri/lib/hooks/use-settings.tsx
index a8f238eae..0c34b9704 100644
--- a/screenpipe-app-tauri/lib/hooks/use-settings.tsx
+++ b/screenpipe-app-tauri/lib/hooks/use-settings.tsx
@@ -86,6 +86,7 @@ export type Settings = {
showScreenpipeShortcut: string;
startRecordingShortcut: string;
stopRecordingShortcut: string;
+ pipeShortcuts: Record<string, string>;
};
const DEFAULT_SETTINGS: Settings = {
@@ -138,6 +139,7 @@ const DEFAULT_SETTINGS: Settings = {
showScreenpipeShortcut: "Super+Alt+S",
startRecordingShortcut: "Super+Alt+R",
stopRecordingShortcut: "Super+Alt+X",
+ pipeShortcuts: {},
};
const DEFAULT_IGNORED_WINDOWS_IN_ALL_OS = [
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.lock b/screenpipe-app-tauri/src-tauri/Cargo.lock
index 8cfe54d03..fbfbf4a6c 100755
--- a/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -4966,7 +4966,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "0.22.3"
+version = "0.22.5"
dependencies = [
"anyhow",
"axum",
diff --git a/screenpipe-app-tauri/src-tauri/src/main.rs b/screenpipe-app-tauri/src-tauri/src/main.rs
index 45095bd7b..e329dbbf5 100755
--- a/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -39,6 +39,7 @@ mod analytics;
mod icons;
use crate::analytics::start_analytics;
use crate::llm_sidecar::LLMSidecar;
+use crate::commands::open_pipe_window;
mod commands;
mod llm_sidecar;
@@ -76,6 +77,7 @@ struct ShortcutConfig {
start: String,
stop: String,
profile_shortcuts: HashMap<String, String>,
+ pipe_shortcuts: HashMap<String, String>,
disabled: Vec<String>,
}
@@ -101,6 +103,20 @@ impl ShortcutConfig {
Err(_) => HashMap::new()
};
+ let pipe_shortcuts = store
+ .keys()
+ .into_iter()
+ .filter_map(|key| {
+ if key.starts_with("pipeShortcuts.") {
+ store.get(key.clone())
+ .and_then(|v| v.as_str().map(String::from))
+ .map(|v| (key.trim_start_matches("pipeShortcuts.").to_string(), v.to_string()))
+ } else {
+ None
+ }
+ })
+ .collect::<HashMap<String, String>>();
+
Ok(Self {
show: store
.get("showScreenpipeShortcut")
@@ -115,6 +131,7 @@ impl ShortcutConfig {
.and_then(|v| v.as_str().map(String::from))
.unwrap_or_else(|| "Alt+Shift+S".to_string()),
profile_shortcuts,
+ pipe_shortcuts,
disabled: store
.get("disabledShortcuts")
.and_then(|v| serde_json::from_value(v.clone()).ok())
@@ -159,12 +176,14 @@ async fn update_global_shortcuts(
start_shortcut: String,
stop_shortcut: String,
profile_shortcuts: HashMap<String, String>,
+ pipe_shortcuts: HashMap<String, String>,
) -> Result<(), String> {
let config = ShortcutConfig {
show: show_shortcut,
start: start_shortcut,
stop: stop_shortcut,
profile_shortcuts,
+ pipe_shortcuts,
disabled: ShortcutConfig::from_store(&app).await?.disabled,
};
apply_shortcuts(&app, &config).await
@@ -222,11 +241,9 @@ async fn apply_shortcuts(app: &AppHandle, config: &ShortcutConfig) -> Result<(),
},
)
.await?;
- info!("applying shortcuts for profiles {:?}", config.profile_shortcuts);
- // Register only non-empty profile shortcuts
+
+ // Register profile shortcuts
for (profile, shortcut) in &config.profile_shortcuts {
- info!("profile: {}", profile);
- info!("shortcut: {}", shortcut);
if !shortcut.is_empty() {
let profile = profile.clone();
register_shortcut(app, shortcut, false, move |app| {
@@ -237,6 +254,26 @@ async fn apply_shortcuts(app: &AppHandle, config: &ShortcutConfig) -> Result<(),
}
}
+ info!("pipe_shortcuts: {:?}", config.pipe_shortcuts);
+
+ // Register pipe shortcuts
+ for (pipe_id, shortcut) in &config.pipe_shortcuts {
+ if !shortcut.is_empty() {
+ let pipe_id = pipe_id.clone();
+ let shortcut_id = format!("pipe_{}", pipe_id);
+ info!(
+ "registering pipe shortcut for pipe: {}, is disabled: {}",
+ shortcut_id,
+ config.is_disabled(&shortcut_id)
+ );
+ register_shortcut(app, shortcut, config.is_disabled(&shortcut_id), move |app| {
+ info!("pipe shortcut triggered for pipe: {}", pipe_id);
+ let _ = app.emit("open-pipe", pipe_id.clone());
+ })
+ .await?;
+ }
+ }
+
Ok(())
}