Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
feat(hotkey): add listening mode to prevent hotkey conflicts during capture, fallback system with user notifications, and cross-platform accessibility settings opener
Gabriel Steinb905a5b97693
diff --git a/CLAUDE.md b/CLAUDE.mdindex 5ca6c3363..9ceb4bbbf 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -49,6 +49,9 @@ OpenWhispr is an Electron-based desktop dictation application that uses whisper.- **dragManager.js**: Window dragging functionality- **environment.js**: Environment variable and OpenAI API management- **hotkeyManager.js**: Global hotkey registration and management+ - Handles platform-specific defaults (GLOBE on macOS, backtick on Windows/Linux)+ - Auto-fallback to F8/F9 if default hotkey is unavailable+ - Notifies renderer via IPC when hotkey registration fails- **ipcHandlers.js**: Centralized IPC handler registration- **menuManager.js**: Application menu management- **tray.js**: System tray icon and menu@@ -75,6 +78,7 @@ OpenWhispr is an Electron-based desktop dictation application that uses whisper.- **usePermissions.ts**: System permission checks and settings access- `openMicPrivacySettings()`: Opens OS microphone privacy settings- `openSoundInputSettings()`: Opens OS sound input device settings+ - `openAccessibilitySettings()`: Opens OS accessibility settings (macOS only)- **useSettings.ts**: Application settings management- **useWhisper.ts**: Whisper binary availability check@@ -235,18 +239,19 @@ All AI model definitions are centralized in `src/models/modelRegistryData.json`### 10. System Settings Integration-The app can open OS-level settings for microphone permissions and sound input selection:+The app can open OS-level settings for microphone permissions, sound input selection, and accessibility:**IPC Handlers** (in `ipcHandlers.js`):- `open-microphone-settings`: Opens microphone privacy settings- `open-sound-input-settings`: Opens sound/audio input device settings+- `open-accessibility-settings`: Opens accessibility privacy settings (macOS only)**Platform-specific URLs**:-| Platform | Microphone Privacy | Sound Input |-|----------|-------------------|-------------|-| macOS | `x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone` | `x-apple.systempreferences:com.apple.preference.sound?input` |-| Windows | `ms-settings:privacy-microphone` | `ms-settings:sound` |-| Linux | Manual (no URL scheme) | Manual (e.g., pavucontrol) |+| Platform | Microphone Privacy | Sound Input | Accessibility |+|----------|-------------------|-------------|---------------|+| macOS | `x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone` | `x-apple.systempreferences:com.apple.preference.sound?input` | `x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility` |+| Windows | `ms-settings:privacy-microphone` | `ms-settings:sound` | N/A |+| Linux | Manual (no URL scheme) | Manual (e.g., pavucontrol) | N/A |**UI Component** (`MicPermissionWarning.tsx`):- Shows platform-appropriate buttons and messagesdiff --git a/preload.js b/preload.jsindex 9e4707c46..f8295fe58 100644--- a/preload.js+++ b/preload.js@@ -105,6 +105,7 @@ contextBridge.exposeInMainWorld("electronAPI", {// Cleanup functioncleanupApp: () => ipcRenderer.invoke("cleanup-app"),updateHotkey: (hotkey) => ipcRenderer.invoke("update-hotkey", hotkey),+ setHotkeyListeningMode: (enabled) => ipcRenderer.invoke("set-hotkey-listening-mode", enabled),startWindowDrag: () => ipcRenderer.invoke("start-window-drag"),stopWindowDrag: () => ipcRenderer.invoke("stop-window-drag"),setMainWindowInteractivity: (interactive) =>@@ -173,6 +174,7 @@ contextBridge.exposeInMainWorld("electronAPI", {// System settings helpers for microphone/audio permissionsopenMicrophoneSettings: () => ipcRenderer.invoke("open-microphone-settings"),openSoundInputSettings: () => ipcRenderer.invoke("open-sound-input-settings"),+ openAccessibilitySettings: () => ipcRenderer.invoke("open-accessibility-settings"),// Globe key listener for hotkey capture (macOS only)onGlobeKeyPressed: (callback) => {@@ -181,6 +183,18 @@ contextBridge.exposeInMainWorld("electronAPI", {return () => ipcRenderer.removeListener("globe-key-pressed", listener);},+ // Hotkey registration events (for notifying user when hotkey fails)+ onHotkeyFallbackUsed: (callback) => {+ const listener = (_event, data) => callback?.(data);+ ipcRenderer.on("hotkey-fallback-used", listener);+ return () => ipcRenderer.removeListener("hotkey-fallback-used", listener);+ },+ onHotkeyRegistrationFailed: (callback) => {+ const listener = (_event, data) => callback?.(data);+ ipcRenderer.on("hotkey-registration-failed", listener);+ return () => ipcRenderer.removeListener("hotkey-registration-failed", listener);+ },+// Remove all listeners for a channelremoveAllListeners: (channel) => {ipcRenderer.removeAllListeners(channel);diff --git a/src/App.jsx b/src/App.jsxindex c8be8c7e4..ee7afcb8e 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -87,6 +87,29 @@ export default function App() {return () => setWindowInteractivity(false);}, [setWindowInteractivity]);+ useEffect(() => {+ const unsubscribeFallback = window.electronAPI?.onHotkeyFallbackUsed?.((data) => {+ toast({+ title: "Hotkey Changed",+ description: data.message,+ duration: 8000,+ });+ });++ const unsubscribeFailed = window.electronAPI?.onHotkeyRegistrationFailed?.((data) => {+ toast({+ title: "Hotkey Unavailable",+ description: `Could not register hotkey. Please set a different hotkey in Settings.`,+ duration: 10000,+ });+ });++ return () => {+ unsubscribeFallback?.();+ unsubscribeFailed?.();+ };+ }, [toast]);+useEffect(() => {if (isCommandMenuOpen) {setWindowInteractivity(true);diff --git a/src/components/OnboardingFlow.tsx b/src/components/OnboardingFlow.tsxindex 7ebbc3d8e..4be238d75 100644--- a/src/components/OnboardingFlow.tsx+++ b/src/components/OnboardingFlow.tsx@@ -791,6 +791,7 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {granted={permissionsHook.accessibilityPermissionGranted}onRequest={permissionsHook.testAccessibilityPermission}buttonText="Test & Grant"+ onOpenSettings={permissionsHook.openAccessibilitySettings}/>)}diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsxindex 1fe64b8b9..c7b5b8fb4 100644--- a/src/components/SettingsPage.tsx+++ b/src/components/SettingsPage.tsx@@ -343,10 +343,7 @@ export default function SettingsPage({ activeSection = "general" }: SettingsPage"Opening System Settings... Look for the Accessibility section under Privacy & Security.",});- window.open(- "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility",- "_blank"- );+ permissionsHook.openAccessibilitySettings();},});};diff --git a/src/components/ui/HotkeyInput.tsx b/src/components/ui/HotkeyInput.tsxindex 06c5e8cd9..4fdbcbbe2 100644--- a/src/components/ui/HotkeyInput.tsx+++ b/src/components/ui/HotkeyInput.tsx@@ -199,12 +199,14 @@ export function HotkeyInput({const handleFocus = useCallback(() => {if (!disabled) {setIsCapturing(true);+ window.electronAPI?.setHotkeyListeningMode?.(true);}}, [disabled]);const handleBlur = useCallback(() => {setIsCapturing(false);setActiveModifiers(new Set());+ window.electronAPI?.setHotkeyListeningMode?.(false);onBlur?.();}, [onBlur]);@@ -214,6 +216,12 @@ export function HotkeyInput({}}, [autoFocus]);+ useEffect(() => {+ return () => {+ window.electronAPI?.setHotkeyListeningMode?.(false);+ };+ }, []);+useEffect(() => {if (!isCapturing || !isMac) return;diff --git a/src/components/ui/PermissionCard.tsx b/src/components/ui/PermissionCard.tsxindex 5b7ce7925..997b3436d 100644--- a/src/components/ui/PermissionCard.tsx+++ b/src/components/ui/PermissionCard.tsx@@ -1,6 +1,6 @@import React from "react";import { Button } from "./button";-import { Check, LucideIcon } from "lucide-react";+import { Check, LucideIcon, Settings } from "lucide-react";interface PermissionCardProps {icon: LucideIcon;@@ -9,6 +9,8 @@ interface PermissionCardProps {granted: boolean;onRequest: () => void;buttonText?: string;+ onOpenSettings?: () => void;+ openSettingsText?: string;}export default function PermissionCard({@@ -18,6 +20,8 @@ export default function PermissionCard({granted,onRequest,buttonText = "Grant Access",+ onOpenSettings,+ openSettingsText = "Open Settings",}: PermissionCardProps) {return (<div className="border rounded-lg p-4">@@ -34,9 +38,17 @@ export default function PermissionCard({<Check className="w-5 h-5" /></div>) : (- <Button onClick={onRequest} size="sm">- {buttonText}- </Button>+ <div className="flex items-center gap-2">+ <Button onClick={onRequest} size="sm">+ {buttonText}+ </Button>+ {onOpenSettings && (+ <Button onClick={onOpenSettings} size="sm" variant="outline">+ <Settings className="w-4 h-4 mr-1" />+ {openSettingsText}+ </Button>+ )}+ </div>)}</div></div>diff --git a/src/helpers/hotkeyManager.js b/src/helpers/hotkeyManager.jsindex 1c9456c74..6c3249085 100644--- a/src/helpers/hotkeyManager.js+++ b/src/helpers/hotkeyManager.js@@ -16,13 +16,19 @@ class HotkeyManager {constructor() {this.currentHotkey = "`";this.isInitialized = false;+ this.isListeningMode = false;+ }++ setListeningMode(enabled) {+ this.isListeningMode = enabled;+ debugLogger.log(`[HotkeyManager] Listening mode: ${enabled ? "enabled" : "disabled"}`);+ }++ isInListeningMode() {+ return this.isListeningMode;}- /**- * Get a helpful error message based on the failure reason- */getFailureReason(hotkey) {- // Check if the hotkey is already registered by usif (globalShortcut.isRegistered(hotkey)) {return {reason: "already_registered",@@ -31,7 +37,6 @@ class HotkeyManager {};}- // Platform-specific checksif (process.platform === "win32") {// Windows reserves certain keysconst winReserved = ["PrintScreen", "Win", "Super"];@@ -55,7 +60,6 @@ class HotkeyManager {}}- // Generic failure - could be another app holding itreturn {reason: "registration_failed",message: `Could not register "${hotkey}". It may be in use by another application.`,@@ -72,7 +76,6 @@ class HotkeyManager {? [...SUGGESTED_HOTKEYS.compound]: [...SUGGESTED_HOTKEYS.single];- // Filter out the failed hotkey if it's in the suggestionsreturn suggestions.filter((s) => s !== failedHotkey).slice(0, 3);}@@ -83,7 +86,17 @@ class HotkeyManager {debugLogger.log(`[HotkeyManager] Setting up hotkey: "${hotkey}"`);debugLogger.log(`[HotkeyManager] Platform: ${process.platform}, Arch: ${process.arch}`);+ debugLogger.log(`[HotkeyManager] Current hotkey: "${this.currentHotkey}"`);++ // If we're already using this hotkey, just return success+ if (hotkey === this.currentHotkey) {+ debugLogger.log(+ `[HotkeyManager] Hotkey "${hotkey}" is already the current hotkey, no change needed`+ );+ return { success: true, hotkey };+ }+ // Unregister the previous hotkey (if it's not GLOBE, which doesn't use globalShortcut)if (this.currentHotkey && this.currentHotkey !== "GLOBE") {debugLogger.log(`[HotkeyManager] Unregistering previous hotkey: "${this.currentHotkey}"`);globalShortcut.unregister(this.currentHotkey);@@ -103,11 +116,9 @@ class HotkeyManager {return { success: true, hotkey };}- // Check if already registered before attemptingconst alreadyRegistered = globalShortcut.isRegistered(hotkey);debugLogger.log(`[HotkeyManager] Is "${hotkey}" already registered? ${alreadyRegistered}`);- // Register the new hotkeyconst success = globalShortcut.register(hotkey, callback);debugLogger.log(`[HotkeyManager] Registration result for "${hotkey}": ${success}`);@@ -120,7 +131,6 @@ class HotkeyManager {console.error(`[HotkeyManager] Failed to register hotkey: ${hotkey}`, failureInfo);debugLogger.log(`[HotkeyManager] Registration failed:`, failureInfo);- // Build user-friendly error message with suggestionslet errorMessage = failureInfo.message;if (failureInfo.suggestions.length > 0) {errorMessage += ` Try: ${failureInfo.suggestions.join(", ")}`;@@ -145,33 +155,105 @@ class HotkeyManager {throw new Error("mainWindow and callback are required");}- // Set up default hotkey first- this.setupShortcuts("`", callback);+ this.mainWindow = mainWindow;- // Listen for window to be ready, then get saved hotkeymainWindow.webContents.once("did-finish-load", () => {setTimeout(() => {- this.loadSavedHotkey(mainWindow, callback);+ this.loadSavedHotkeyOrDefault(mainWindow, callback);}, 1000);});this.isInitialized = true;}- async loadSavedHotkey(mainWindow, callback) {+ async loadSavedHotkeyOrDefault(mainWindow, callback) {try {const savedHotkey = await mainWindow.webContents.executeJavaScript(`- localStorage.getItem("dictationKey") || "\`"+ localStorage.getItem("dictationKey") || ""`);- if (savedHotkey && savedHotkey !== "`") {+ if (savedHotkey && savedHotkey.trim() !== "") {const result = this.setupShortcuts(savedHotkey, callback);if (result.success) {- // Hotkey initialized from localStorage+ debugLogger.log(`[HotkeyManager] Restored saved hotkey: "${savedHotkey}"`);+ return;+ }+ debugLogger.log(`[HotkeyManager] Saved hotkey "${savedHotkey}" failed to register`);+ this.notifyHotkeyFailure(savedHotkey, result);+ }++ const defaultHotkey = process.platform === "darwin" ? "GLOBE" : "`";++ if (defaultHotkey === "GLOBE") {+ this.currentHotkey = "GLOBE";+ debugLogger.log("[HotkeyManager] Using GLOBE key as default on macOS");+ return;+ }++ const result = this.setupShortcuts(defaultHotkey, callback);+ if (result.success) {+ debugLogger.log(+ `[HotkeyManager] Default hotkey "${defaultHotkey}" registered successfully`+ );+ return;+ }++ debugLogger.log(+ `[HotkeyManager] Default hotkey "${defaultHotkey}" failed, trying fallbacks...`+ );+ const fallbackHotkeys = ["F8", "F9", "CommandOrControl+Shift+Space"];++ for (const fallback of fallbackHotkeys) {+ const fallbackResult = this.setupShortcuts(fallback, callback);+ if (fallbackResult.success) {+ debugLogger.log(`[HotkeyManager] Fallback hotkey "${fallback}" registered successfully`);+ // Save the working fallback to localStorage+ this.saveHotkeyToRenderer(fallback);+ // Notify renderer about the fallback+ this.notifyHotkeyFallback(defaultHotkey, fallback);+ return;}}++ debugLogger.log("[HotkeyManager] All hotkey fallbacks failed");+ this.notifyHotkeyFailure(defaultHotkey, result);} catch (err) {- console.error("Failed to get saved hotkey:", err);+ console.error("Failed to initialize hotkey:", err);+ debugLogger.error("[HotkeyManager] Failed to initialize hotkey:", err);+ }+ }++ saveHotkeyToRenderer(hotkey) {+ if (this.mainWindow && !this.mainWindow.isDestroyed()) {+ this.mainWindow.webContents+ .executeJavaScript(+ `+ localStorage.setItem("dictationKey", "${hotkey}");+ `+ )+ .catch((err) => {+ debugLogger.error("[HotkeyManager] Failed to save hotkey to localStorage:", err);+ });+ }+ }++ notifyHotkeyFallback(originalHotkey, fallbackHotkey) {+ if (this.mainWindow && !this.mainWindow.isDestroyed()) {+ this.mainWindow.webContents.send("hotkey-fallback-used", {+ original: originalHotkey,+ fallback: fallbackHotkey,+ message: `The "${originalHotkey}" key was unavailable. Using "${fallbackHotkey}" instead. You can change this in Settings.`,+ });+ }+ }++ notifyHotkeyFailure(hotkey, result) {+ if (this.mainWindow && !this.mainWindow.isDestroyed()) {+ this.mainWindow.webContents.send("hotkey-registration-failed", {+ hotkey,+ error: result?.error || `Could not register "${hotkey}"`,+ suggestions: result?.suggestions || ["F8", "F9", "CommandOrControl+Shift+Space"],+ });}}diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex e4588ba88..2bbd9758d 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -258,6 +258,11 @@ class IPCHandlers {return await this.windowManager.updateHotkey(hotkey);});+ ipcMain.handle("set-hotkey-listening-mode", async (event, enabled) => {+ this.windowManager.setHotkeyListeningMode(enabled);+ return { success: true };+ });+ipcMain.handle("start-window-drag", async (event) => {return await this.windowManager.startWindowDrag();});@@ -519,6 +524,8 @@ class IPCHandlers {darwin: {microphone: "x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone",sound: "x-apple.systempreferences:com.apple.preference.sound?input",+ accessibility:+ "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility",},win32: {microphone: "ms-settings:privacy-microphone",@@ -529,20 +536,24 @@ class IPCHandlers {const openSystemSettings = async (settingType) => {const platform = process.platform;const urls = SYSTEM_SETTINGS_URLS[platform];-- if (!urls) {- // Linux doesn't have standardized URL schemes for system settings+ const url = urls?.[settingType];++ if (!url) {+ // Platform doesn't support this settings URL+ const messages = {+ microphone: "Please open your system settings to configure microphone permissions.",+ sound: "Please open your system sound settings (e.g., pavucontrol).",+ accessibility: "Accessibility settings are not applicable on this platform.",+ };return {success: false,error:- settingType === "microphone"- ? "Please open your system settings to configure microphone permissions."- : "Please open your system sound settings (e.g., pavucontrol).",+ messages[settingType] || `${settingType} settings are not available on this platform.`,};}try {- await shell.openExternal(urls[settingType]);+ await shell.openExternal(url);return { success: true };} catch (error) {debugLogger.error(`Failed to open ${settingType} settings:`, error);@@ -552,6 +563,7 @@ class IPCHandlers {ipcMain.handle("open-microphone-settings", () => openSystemSettings("microphone"));ipcMain.handle("open-sound-input-settings", () => openSystemSettings("sound"));+ ipcMain.handle("open-accessibility-settings", () => openSystemSettings("accessibility"));}broadcastToWindows(channel, payload) {diff --git a/src/helpers/windowManager.js b/src/helpers/windowManager.jsindex 35c759459..15f9500a8 100644--- a/src/helpers/windowManager.js+++ b/src/helpers/windowManager.js@@ -109,6 +109,10 @@ class WindowManager {const DEBOUNCE_MS = 150;return () => {+ if (this.hotkeyManager.isInListeningMode()) {+ return;+ }+const now = Date.now();if (now - lastToggleTime < DEBOUNCE_MS) {return;@@ -122,6 +126,10 @@ class WindowManager {};}+ setHotkeyListeningMode(enabled) {+ this.hotkeyManager.setListeningMode(enabled);+ }+async initializeHotkey() {await this.hotkeyManager.initializeHotkey(this.mainWindow, this.createHotkeyCallback());}diff --git a/src/hooks/usePermissions.ts b/src/hooks/usePermissions.tsindex 41a113c18..9d6ae9488 100644--- a/src/hooks/usePermissions.ts+++ b/src/hooks/usePermissions.ts@@ -14,6 +14,7 @@ export interface UsePermissionsReturn {checkPasteToolsAvailability: () => Promise<PasteToolsResult | null>;openMicPrivacySettings: () => Promise<void>;openSoundInputSettings: () => Promise<void>;+ openAccessibilitySettings: () => Promise<void>;setMicPermissionGranted: (granted: boolean) => void;setAccessibilityPermissionGranted: (granted: boolean) => void;}@@ -106,12 +107,13 @@ export const usePermissions = (const openSystemSettings = useCallback(async (- settingType: "microphone" | "sound",+ settingType: "microphone" | "sound" | "accessibility",apiMethod: () => Promise<{ success: boolean; error?: string } | undefined> | undefined) => {const titles = {microphone: "Microphone Settings",sound: "Sound Settings",+ accessibility: "Accessibility Settings",};try {const result = await apiMethod?.();@@ -139,6 +141,11 @@ export const usePermissions = ([openSystemSettings]);+ const openAccessibilitySettings = useCallback(+ () => openSystemSettings("accessibility", window.electronAPI?.openAccessibilitySettings),+ [openSystemSettings]+ );+const requestMicPermission = useCallback(async () => {if (!navigator?.mediaDevices || typeof navigator.mediaDevices.getUserMedia !== "function") {const message =@@ -296,6 +303,7 @@ export const usePermissions = (checkPasteToolsAvailability,openMicPrivacySettings,openSoundInputSettings,+ openAccessibilitySettings,setMicPermissionGranted,setAccessibilityPermissionGranted,};diff --git a/src/types/electron.ts b/src/types/electron.tsindex 85f4d9de2..323739496 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -237,10 +237,19 @@ declare global {// Hotkey managementupdateHotkey: (key: string) => Promise<{ success: boolean; message: string }>;+ setHotkeyListeningMode?: (enabled: boolean) => Promise<{ success: boolean }>;// Globe key listener for hotkey capture (macOS only)onGlobeKeyPressed?: (callback: () => void) => () => void;+ // Hotkey registration events+ onHotkeyFallbackUsed?: (+ callback: (data: { original: string; fallback: string; message: string }) => void+ ) => () => void;+ onHotkeyRegistrationFailed?: (+ callback: (data: { hotkey: string; error: string; suggestions: string[] }) => void+ ) => () => void;+// Gemini API key managementgetGeminiKey: () => Promise<string | null>;saveGeminiKey: (key: string) => Promise<void>;@@ -265,6 +274,7 @@ declare global {// System settings helpersopenMicrophoneSettings?: () => Promise<{ success: boolean; error?: string }>;openSoundInputSettings?: () => Promise<{ success: boolean; error?: string }>;+ openAccessibilitySettings?: () => Promise<{ success: boolean; error?: string }>;};api?: {