Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

feat: add cross-platform paste tools detection for Linux/Windows onboarding with auto-grant accessibility

Gabriel Steinddf608c531ee
diff --git a/preload.js b/preload.js
index 557c34ffb..401962557 100644
--- a/preload.js
+++ b/preload.js
@@ -68,6 +68,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
// Clipboard functions
readClipboard: () => ipcRenderer.invoke("read-clipboard"),
writeClipboard: (text) => ipcRenderer.invoke("write-clipboard", text),
+ checkPasteTools: () => ipcRenderer.invoke("check-paste-tools"),
// Python installation functions
checkPythonInstallation: () =>
diff --git a/src/components/OnboardingFlow.tsx b/src/components/OnboardingFlow.tsx
index 8ba08f9dc..ca2de274b 100644
--- a/src/components/OnboardingFlow.tsx
+++ b/src/components/OnboardingFlow.tsx
@@ -25,6 +25,7 @@ import ProcessingModeSelector from "./ui/ProcessingModeSelector";
import ApiKeyInput from "./ui/ApiKeyInput";
import PermissionCard from "./ui/PermissionCard";
import MicPermissionWarning from "./ui/MicPermissionWarning";
+import PasteToolsInfo from "./ui/PasteToolsInfo";
import StepProgress from "./ui/StepProgress";
import { AlertDialog, ConfirmDialog } from "./ui/dialog";
import { useLocalStorage } from "../hooks/useLocalStorage";
@@ -869,12 +870,17 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
);
case 3: // Permissions
+ const platform = permissionsHook.pasteToolsInfo?.platform;
+ const isMacOS = platform === "darwin";
+
return (
<div className="space-y-6">
<div className="text-center">
<h2 className="text-2xl font-bold text-gray-900 mb-2">Grant Permissions</h2>
<p className="text-gray-600">
- OpenWhispr needs a couple of permissions to work properly
+ {isMacOS
+ ? "OpenWhispr needs a couple of permissions to work properly"
+ : "OpenWhispr needs microphone access to record your voice"}
</p>
</div>
@@ -896,14 +902,24 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
/>
)}
- <PermissionCard
- icon={Shield}
- title="Accessibility Permission"
- description="Required to paste text automatically"
- granted={permissionsHook.accessibilityPermissionGranted}
- onRequest={permissionsHook.testAccessibilityPermission}
- buttonText="Test & Grant"
- />
+ {isMacOS && (
+ <PermissionCard
+ icon={Shield}
+ title="Accessibility Permission"
+ description="Required to paste text automatically"
+ granted={permissionsHook.accessibilityPermissionGranted}
+ onRequest={permissionsHook.testAccessibilityPermission}
+ buttonText="Test & Grant"
+ />
+ )}
+
+ {!isMacOS && (
+ <PasteToolsInfo
+ pasteToolsInfo={permissionsHook.pasteToolsInfo}
+ isChecking={permissionsHook.isCheckingPasteTools}
+ onCheck={permissionsHook.checkPasteToolsAvailability}
+ />
+ )}
</div>
<div className="bg-amber-50 p-4 rounded-lg">
@@ -1175,10 +1191,16 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
}
return customReasoningModels.length > 0 && !customModelsLoading && !customModelsError;
}
- case 3:
- return (
- permissionsHook.micPermissionGranted && permissionsHook.accessibilityPermissionGranted
- );
+ case 3: {
+ if (!permissionsHook.micPermissionGranted) {
+ return false;
+ }
+ const currentPlatform = permissionsHook.pasteToolsInfo?.platform;
+ if (currentPlatform === "darwin") {
+ return permissionsHook.accessibilityPermissionGranted;
+ }
+ return true;
+ }
case 4:
return hotkey.trim() !== "";
case 5:
diff --git a/src/components/ui/PasteToolsInfo.tsx b/src/components/ui/PasteToolsInfo.tsx
new file mode 100644
index 000000000..f5f09359f
--- /dev/null
+++ b/src/components/ui/PasteToolsInfo.tsx
@@ -0,0 +1,136 @@
+import { Check, Terminal, Info } from "lucide-react";
+import { Button } from "./button";
+import type { PasteToolsResult } from "../../types/electron";
+
+interface PasteToolsInfoProps {
+ pasteToolsInfo: PasteToolsResult | null;
+ isChecking: boolean;
+ onCheck: () => void;
+}
+
+export default function PasteToolsInfo({
+ pasteToolsInfo,
+ isChecking,
+ onCheck,
+}: PasteToolsInfoProps) {
+ if (!pasteToolsInfo) {
+ return (
+ <div className="border rounded-lg p-4">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-3">
+ <Terminal className="w-6 h-6 text-indigo-600" />
+ <div>
+ <h3 className="font-semibold text-gray-900">Automatic Pasting</h3>
+ <p className="text-sm text-gray-600">Checking system capabilities...</p>
+ </div>
+ </div>
+ {isChecking && (
+ <div className="animate-spin rounded-full h-5 w-5 border-b-2 border-indigo-600"></div>
+ )}
+ </div>
+ </div>
+ );
+ }
+
+ // Windows - always ready
+ if (pasteToolsInfo.platform === "win32") {
+ return (
+ <div className="border border-green-200 bg-green-50 rounded-lg p-4">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-3">
+ <Terminal className="w-6 h-6 text-green-600" />
+ <div>
+ <h3 className="font-semibold text-green-900">Automatic Pasting Ready</h3>
+ <p className="text-sm text-green-700">
+ Windows supports automatic pasting out of the box. No setup required!
+ </p>
+ </div>
+ </div>
+ <div className="text-green-600">
+ <Check className="w-5 h-5" />
+ </div>
+ </div>
+ </div>
+ );
+ }
+
+ // Linux with tools available
+ if (pasteToolsInfo.platform === "linux" && pasteToolsInfo.available) {
+ return (
+ <div className="border border-green-200 bg-green-50 rounded-lg p-4">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-3">
+ <Terminal className="w-6 h-6 text-green-600" />
+ <div>
+ <h3 className="font-semibold text-green-900">Automatic Pasting Ready</h3>
+ <p className="text-sm text-green-700">
+ Using <code className="bg-green-100 px-1 rounded">{pasteToolsInfo.method}</code> for
+ automatic text pasting.
+ </p>
+ </div>
+ </div>
+ <div className="text-green-600">
+ <Check className="w-5 h-5" />
+ </div>
+ </div>
+ </div>
+ );
+ }
+
+ // Linux without tools - show helpful install instructions
+ if (pasteToolsInfo.platform === "linux" && !pasteToolsInfo.available) {
+ const isWayland = pasteToolsInfo.isWayland;
+ const recommendedTool = pasteToolsInfo.recommendedInstall || (isWayland ? "wtype" : "xdotool");
+
+ return (
+ <div className="border border-amber-200 bg-amber-50 rounded-lg p-4 space-y-3">
+ <div className="flex items-start gap-3">
+ <Info className="w-6 h-6 text-amber-600 flex-shrink-0 mt-0.5" />
+ <div className="flex-1">
+ <h3 className="font-semibold text-amber-900">Optional: Enable Automatic Pasting</h3>
+ <p className="text-sm text-amber-800 mt-1">
+ For automatic text pasting, install{" "}
+ <code className="bg-amber-100 px-1 rounded font-mono">{recommendedTool}</code>:
+ </p>
+
+ <div className="mt-3 bg-gray-900 text-gray-100 p-3 rounded-md font-mono text-xs overflow-x-auto">
+ {isWayland ? (
+ <>
+ <div className="text-gray-400"># Fedora / RHEL</div>
+ <div>sudo dnf install wtype</div>
+ <div className="text-gray-400 mt-2"># Debian / Ubuntu</div>
+ <div>sudo apt install wtype</div>
+ <div className="text-gray-400 mt-2"># Arch Linux</div>
+ <div>sudo pacman -S wtype</div>
+ </>
+ ) : (
+ <>
+ <div className="text-gray-400"># Debian / Ubuntu / Mint</div>
+ <div>sudo apt install xdotool</div>
+ <div className="text-gray-400 mt-2"># Fedora / RHEL</div>
+ <div>sudo dnf install xdotool</div>
+ <div className="text-gray-400 mt-2"># Arch Linux</div>
+ <div>sudo pacman -S xdotool</div>
+ </>
+ )}
+ </div>
+
+ <p className="text-sm text-amber-700 mt-3">
+ Without this tool, OpenWhispr will copy text to your clipboard. You can then paste
+ manually with <kbd className="bg-amber-100 px-1 rounded text-xs">Ctrl+V</kbd>.
+ </p>
+ </div>
+ </div>
+
+ <div className="flex justify-end">
+ <Button variant="outline" size="sm" onClick={onCheck} disabled={isChecking}>
+ {isChecking ? "Checking..." : "Re-check"}
+ </Button>
+ </div>
+ </div>
+ );
+ }
+
+ // Fallback for macOS (shouldn't normally render this component on macOS)
+ return null;
+}
diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.js
index cb0b25ef5..5661e6529 100644
--- a/src/helpers/clipboard.js
+++ b/src/helpers/clipboard.js
@@ -507,6 +507,74 @@ Would you like to open System Settings now?`;
throw error;
}
}
+
+ /**
+ * Check availability of paste tools on the current platform.
+ * Returns platform-specific information about paste capability.
+ */
+ checkPasteTools() {
+ const platform = process.platform;
+
+ // macOS uses AppleScript - always available, but needs accessibility permission
+ if (platform === "darwin") {
+ return {
+ platform: "darwin",
+ available: true,
+ method: "applescript",
+ requiresPermission: true,
+ tools: [],
+ };
+ }
+
+ // Windows uses PowerShell SendKeys - always available
+ if (platform === "win32") {
+ return {
+ platform: "win32",
+ available: true,
+ method: "powershell",
+ requiresPermission: false,
+ tools: [],
+ };
+ }
+
+ // Linux - check for available paste tools
+ const isWayland =
+ (process.env.XDG_SESSION_TYPE || "").toLowerCase() === "wayland" ||
+ !!process.env.WAYLAND_DISPLAY;
+
+ const commandExists = (cmd) => {
+ try {
+ const res = spawnSync("sh", ["-c", `command -v ${cmd}`], {
+ stdio: "ignore",
+ });
+ return res.status === 0;
+ } catch {
+ return false;
+ }
+ };
+
+ // Check which tools are available
+ const tools = [];
+ const toolsToCheck = isWayland
+ ? ["wtype", "ydotool", "xdotool"] // xdotool as fallback for XWayland
+ : ["xdotool"];
+
+ for (const tool of toolsToCheck) {
+ if (commandExists(tool)) {
+ tools.push(tool);
+ }
+ }
+
+ return {
+ platform: "linux",
+ available: tools.length > 0,
+ method: tools.length > 0 ? tools[0] : null,
+ requiresPermission: false,
+ isWayland,
+ tools,
+ recommendedInstall: isWayland ? "wtype" : "xdotool",
+ };
+ }
}
module.exports = ClipboardManager;
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 21d5989ba..058fb3bbb 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -141,6 +141,10 @@ class IPCHandlers {
return this.clipboardManager.writeClipboard(text);
});
+ ipcMain.handle("check-paste-tools", async () => {
+ return this.clipboardManager.checkPasteTools();
+ });
+
// Whisper handlers
ipcMain.handle("transcribe-local-whisper", async (event, audioBlob, options = {}) => {
debugLogger.log("transcribe-local-whisper called", {
diff --git a/src/hooks/usePermissions.ts b/src/hooks/usePermissions.ts
index 60c87f78c..b6b291b69 100644
--- a/src/hooks/usePermissions.ts
+++ b/src/hooks/usePermissions.ts
@@ -1,13 +1,17 @@
-import { useState, useCallback } from "react";
+import { useState, useCallback, useEffect } from "react";
+import type { PasteToolsResult } from "../types/electron";
export interface UsePermissionsReturn {
// State
micPermissionGranted: boolean;
accessibilityPermissionGranted: boolean;
micPermissionError: string | null;
+ pasteToolsInfo: PasteToolsResult | null;
+ isCheckingPasteTools: boolean;
requestMicPermission: () => Promise<void>;
testAccessibilityPermission: () => Promise<void>;
+ checkPasteToolsAvailability: () => Promise<PasteToolsResult | null>;
openMicPrivacySettings: () => Promise<void>;
openSoundInputSettings: () => Promise<void>;
setMicPermissionGranted: (granted: boolean) => void;
@@ -44,6 +48,23 @@ const getPlatformPrivacyPath = (): string => {
return "System Settings → Privacy & Security → Microphone";
};
+const getPlatform = (): "darwin" | "win32" | "linux" => {
+ if (typeof window !== "undefined" && window.electronAPI?.getPlatform) {
+ const platform = window.electronAPI.getPlatform();
+ if (platform === "darwin" || platform === "win32" || platform === "linux") {
+ return platform;
+ }
+ }
+ // Fallback to user agent detection
+ if (typeof navigator !== "undefined") {
+ const ua = navigator.userAgent.toLowerCase();
+ if (ua.includes("mac")) return "darwin";
+ if (ua.includes("win")) return "win32";
+ if (ua.includes("linux")) return "linux";
+ }
+ return "darwin"; // Default fallback
+};
+
const describeMicError = (error: unknown): string => {
if (!error || typeof error !== "object") {
return "Microphone access failed. Please try again.";
@@ -80,6 +101,8 @@ export const usePermissions = (
const [micPermissionGranted, setMicPermissionGranted] = useState(false);
const [micPermissionError, setMicPermissionError] = useState<string | null>(null);
const [accessibilityPermissionGranted, setAccessibilityPermissionGranted] = useState(false);
+ const [pasteToolsInfo, setPasteToolsInfo] = useState<PasteToolsResult | null>(null);
+ const [isCheckingPasteTools, setIsCheckingPasteTools] = useState(false);
const openMicPrivacySettings = useCallback(async () => {
try {
@@ -135,41 +158,123 @@ export const usePermissions = (
}
}, [showAlertDialog]);
- const testAccessibilityPermission = useCallback(async () => {
+ const checkPasteToolsAvailability = useCallback(async (): Promise<PasteToolsResult | null> => {
+ setIsCheckingPasteTools(true);
try {
- await window.electronAPI.pasteText("OpenWhispr accessibility test");
+ if (window.electronAPI?.checkPasteTools) {
+ const result = await window.electronAPI.checkPasteTools();
+ setPasteToolsInfo(result);
+
+ // On Windows and Linux with tools available, auto-grant accessibility
+ if (result.platform === "win32") {
+ setAccessibilityPermissionGranted(true);
+ } else if (result.platform === "linux" && result.available) {
+ setAccessibilityPermissionGranted(true);
+ }
+ return result;
+ }
+ return null;
+ } catch (error) {
+ console.error("Failed to check paste tools:", error);
+ return null;
+ } finally {
+ setIsCheckingPasteTools(false);
+ }
+ }, []);
+
+ // Check paste tools on mount
+ useEffect(() => {
+ checkPasteToolsAvailability();
+ }, [checkPasteToolsAvailability]);
+
+ const testAccessibilityPermission = useCallback(async () => {
+ const platform = getPlatform();
+
+ // On macOS, actually test the accessibility permission
+ if (platform === "darwin") {
+ try {
+ await window.electronAPI.pasteText("OpenWhispr accessibility test");
+ setAccessibilityPermissionGranted(true);
+ if (showAlertDialog) {
+ showAlertDialog({
+ title: "Accessibility Test Successful",
+ description:
+ "Accessibility permissions working! Check if the test text appeared in another app.",
+ });
+ } else {
+ alert(
+ "Accessibility permissions working! Check if the test text appeared in another app."
+ );
+ }
+ } catch (err) {
+ console.error("Accessibility permission test failed:", err);
+ if (showAlertDialog) {
+ showAlertDialog({
+ title: "Accessibility Permissions Needed",
+ description:
+ "Please grant accessibility permissions in System Settings to enable automatic text pasting.",
+ });
+ } else {
+ alert("Accessibility permissions needed! Please grant them in System Settings.");
+ }
+ }
+ return;
+ }
+
+ // On Windows, PowerShell SendKeys is always available
+ if (platform === "win32") {
setAccessibilityPermissionGranted(true);
if (showAlertDialog) {
showAlertDialog({
- title: "✅ Accessibility Test Successful",
+ title: "Ready to Go!",
description:
- "Accessibility permissions working! Check if the test text appeared in another app.",
+ "Windows doesn't require special permissions for automatic pasting. You're all set!",
});
- } else {
- alert(
- "✅ Accessibility permissions working! Check if the test text appeared in another app."
- );
}
- } catch (err) {
- console.error("Accessibility permission test failed:", err);
- if (showAlertDialog) {
- showAlertDialog({
- title: "❌ Accessibility Permissions Needed",
- description:
- "Please grant accessibility permissions in System Settings to enable automatic text pasting.",
- });
+ return;
+ }
+
+ // On Linux, check if paste tools are available
+ if (platform === "linux") {
+ const result = await checkPasteToolsAvailability();
+
+ if (result?.available) {
+ setAccessibilityPermissionGranted(true);
+ if (showAlertDialog) {
+ showAlertDialog({
+ title: "Ready to Go!",
+ description: `Automatic pasting is available using ${result.method}. You're all set!`,
+ });
+ }
} else {
- alert("❌ Accessibility permissions needed! Please grant them in System Settings.");
+ // Don't block, but inform the user
+ const isWayland = result?.isWayland;
+ const recommendedTool = isWayland ? "wtype" : "xdotool";
+ const installCmd = isWayland
+ ? "sudo dnf install wtype # Fedora\nsudo apt install wtype # Debian/Ubuntu"
+ : "sudo apt install xdotool # Debian/Ubuntu/Mint\nsudo dnf install xdotool # Fedora";
+
+ if (showAlertDialog) {
+ showAlertDialog({
+ title: "Optional: Install Paste Tool",
+ description: `For automatic pasting, install ${recommendedTool}:\n\n${installCmd}\n\nWithout this, you can still use OpenWhispr - text will be copied to your clipboard and you can paste with Ctrl+V.`,
+ });
+ }
+ // Still allow proceeding - this is optional
+ setAccessibilityPermissionGranted(true);
}
}
- }, [showAlertDialog]);
+ }, [showAlertDialog, checkPasteToolsAvailability]);
return {
micPermissionGranted,
accessibilityPermissionGranted,
micPermissionError,
+ pasteToolsInfo,
+ isCheckingPasteTools,
requestMicPermission,
testAccessibilityPermission,
+ checkPasteToolsAvailability,
openMicPrivacySettings,
openSoundInputSettings,
setMicPermissionGranted,
diff --git a/src/types/electron.ts b/src/types/electron.ts
index 2cf03d4c3..f96a3764a 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -104,6 +104,16 @@ export interface PythonInstallProgressData {
percentage: number;
}
+export interface PasteToolsResult {
+ platform: "darwin" | "win32" | "linux";
+ available: boolean;
+ method: string | null;
+ requiresPermission: boolean;
+ isWayland?: boolean;
+ tools?: string[];
+ recommendedInstall?: string;
+}
+
// Additional interface missing from preload.js
export interface SaveSettings {
useLocalWhisper: boolean;
@@ -144,6 +154,7 @@ declare global {
writeClipboard: (text: string) => Promise<{ success: boolean }>;
pasteFromClipboard: () => Promise<{ success: boolean; error?: string }>;
pasteFromClipboardWithFallback: () => Promise<{ success: boolean; error?: string }>;
+ checkPasteTools: () => Promise<PasteToolsResult>;
// Settings
getSettings: () => Promise<any>;