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
fix: dictation hotkey silently dying in hyprland on config reload. (#919)
Idris Gadi70cfe9eebc49
diff --git a/preload.js b/preload.jsindex 42c4b6c71..79166bad5 100644--- a/preload.js+++ b/preload.js@@ -293,6 +293,7 @@ contextBridge.exposeInMainWorld("electronAPI", {setHotkeyListeningMode: (enabled, newHotkey) =>ipcRenderer.invoke("set-hotkey-listening-mode", enabled, newHotkey),getHotkeyModeInfo: () => ipcRenderer.invoke("get-hotkey-mode-info"),+ getHyprlandConfigStatus: () => ipcRenderer.invoke("get-hyprland-config-status"),startWindowDrag: () => ipcRenderer.invoke("start-window-drag"),stopWindowDrag: () => ipcRenderer.invoke("stop-window-drag"),setMainWindowInteractivity: (interactive) =>diff --git a/src/components/OnboardingFlow.tsx b/src/components/OnboardingFlow.tsxindex 3a9aa5827..02cb70e96 100644--- a/src/components/OnboardingFlow.tsx+++ b/src/components/OnboardingFlow.tsx@@ -19,6 +19,7 @@ import PermissionsSection from "./ui/PermissionsSection";import SupportDropdown from "./ui/SupportDropdown";import StepProgress from "./ui/StepProgress";import { AlertDialog, ConfirmDialog } from "./ui/dialog";+import { Alert, AlertDescription, AlertTitle } from "./ui/alert";import { useLocalStorage } from "../hooks/useLocalStorage";import { useDialogs } from "../hooks/useDialogs";import { usePermissions } from "../hooks/usePermissions";@@ -33,6 +34,7 @@ import { formatHotkeyLabel, getDefaultHotkey, isGlobeLikeHotkey } from "../utilsimport { useAuth } from "../hooks/useAuth";import { HotkeyInput } from "./ui/HotkeyInput";import { useHotkeyRegistration } from "../hooks/useHotkeyRegistration";+import { useHotkeyModeInfo } from "../hooks/useHotkeyModeInfo";import { getValidationMessage } from "../utils/hotkeyValidator";import { validateHotkeyForSlot } from "../utils/hotkeyValidation";import { getCachedPlatform, getPlatform } from "../utils/platform";@@ -104,7 +106,8 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {const [skipAuth, setSkipAuth] = useState(false);const [pendingVerificationEmail, setPendingVerificationEmail] = useState<string | null>(null);const [isModelDownloaded, setIsModelDownloaded] = useState(false);- const [isUsingNativeShortcut, setIsUsingNativeShortcut] = useState(false);+ const { isUsingNativeShortcut, isUsingHyprland, hyprlandConfigStatus, supportsPushToTalk } =+ useHotkeyModeInfo("onboarding");const readableHotkey = formatHotkeyLabel(hotkey);const { alertDialog, confirmDialog, showAlertDialog, hideAlertDialog, hideConfirmDialog } =useDialogs();@@ -175,21 +178,10 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {const showProgress = currentStep > 0;useEffect(() => {- const checkHotkeyMode = async () => {- try {- const info = await window.electronAPI?.getHotkeyModeInfo();- if (info?.isUsingNativeShortcut) {- setIsUsingNativeShortcut(true);- if (!info.supportsPushToTalk) {- setActivationMode("tap");- }- }- } catch (error) {- logger.error("Failed to check hotkey mode", { error }, "onboarding");- }- };- checkHotkeyMode();- }, [setActivationMode]);+ if (isUsingNativeShortcut && !supportsPushToTalk) {+ setActivationMode("tap");+ }+ }, [isUsingNativeShortcut, supportsPushToTalk, setActivationMode]);// Update wizard UI when backend falls back to a different hotkey.// Only update local state — don't persist to localStorage so the app@@ -630,14 +622,32 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {<p className="text-xs text-muted-foreground">{t("onboarding.activation.description")}</p></div>+ {isUsingHyprland && hyprlandConfigStatus && !hyprlandConfigStatus.canWrite && (+ <Alert>+ <AlertTitle>+ {t("settingsPage.general.hotkey.hyprlandConfigWriteWarningTitle")}+ </AlertTitle>+ <AlertDescription>+ {t("settingsPage.general.hotkey.hyprlandConfigWriteWarningDescription", {+ path: hyprlandConfigStatus.path,+ })}+ </AlertDescription>+ </Alert>+ )}+{/* Unified control surface */}<div className="rounded-lg border border-border-subtle bg-surface-1 overflow-hidden">{/* Hotkey section */}<div className="p-4 border-b border-border-subtle">- <div className="flex items-center justify-between mb-3">+ <div className="mb-3"><span className="text-xs font-medium text-muted-foreground uppercase tracking-wide">{t("onboarding.activation.hotkey")}</span>+ {isUsingHyprland && (+ <p className="text-xs text-muted-foreground/80 mt-0.5 leading-relaxed">+ {t("settingsPage.general.hotkey.hyprlandUnbindDescription")}+ </p>+ )}</div><HotkeyInputvalue={hotkey}diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsxindex 48f9f063c..ff0504ae5 100644--- a/src/components/SettingsPage.tsx+++ b/src/components/SettingsPage.tsx@@ -66,6 +66,7 @@ import PromptStudio from "./ui/PromptStudio";import { ProviderTabs } from "./ui/ProviderTabs";import { HotkeyInput } from "./ui/HotkeyInput";import { useHotkeyRegistration } from "../hooks/useHotkeyRegistration";+import { useHotkeyModeInfo } from "../hooks/useHotkeyModeInfo";import { useLocalStorage } from "../hooks/useLocalStorage";import { validateHotkeyForSlot } from "../utils/hotkeyValidation";import { getPlatform, getCachedPlatform } from "../utils/platform";@@ -166,13 +167,22 @@ function SettingsPanelRow({);}-function SectionHeader({ title, description }: { title: string; description?: string }) {+function SectionHeader({+ title,+ description,+ note,+}: {+ title: string;+ description?: string;+ note?: string;+}) {return (<div className="mb-3"><h3 className="text-xs font-semibold text-foreground tracking-tight">{title}</h3>{description && (<p className="text-xs text-muted-foreground/80 mt-0.5 leading-relaxed">{description}</p>)}+ {note && <p className="text-xs text-muted-foreground/80 mt-0.5 leading-relaxed">{note}</p>}</div>);}@@ -979,7 +989,8 @@ export default function SettingsPage({[dictationKey, meetingKey, chatAgentKey, t]);- const [isUsingNativeShortcut, setIsUsingNativeShortcut] = useState(false);+ const { isUsingNativeShortcut, isUsingHyprland, hyprlandConfigStatus, supportsPushToTalk } =+ useHotkeyModeInfo("settings");const [effectiveDefaultHotkey, setEffectiveDefaultHotkey] = useState<string | null>(null);const [linuxPttAvailable, setLinuxPttAvailable] = useState(true);@@ -1094,18 +1105,13 @@ export default function SettingsPage({}, [checkWhisperInstallation, getAppVersion]);useEffect(() => {- const checkHotkeyMode = async () => {- try {- const info = await window.electronAPI?.getHotkeyModeInfo();- if (info?.isUsingNativeShortcut) {- setIsUsingNativeShortcut(true);- if (!info.supportsPushToTalk) {- setActivationMode("tap");- }- }- } catch (error) {- logger.error("Failed to check hotkey mode", error, "settings");- }+ if (isUsingNativeShortcut && !supportsPushToTalk) {+ setActivationMode("tap");+ }+ }, [isUsingNativeShortcut, supportsPushToTalk, setActivationMode]);++ useEffect(() => {+ const loadEffectiveDefaultHotkey = async () => {try {const key = await window.electronAPI?.getEffectiveDefaultHotkey?.();if (key) setEffectiveDefaultHotkey(key);@@ -1113,8 +1119,8 @@ export default function SettingsPage({logger.error("Failed to get effective default hotkey", error, "settings");}};- checkHotkeyMode();- }, [setActivationMode]);+ loadEffectiveDefaultHotkey();+ }, []);useEffect(() => {const cleanup = window.electronAPI?.onLinuxPttPermissionDenied?.(() => {@@ -3196,11 +3202,25 @@ EOF`,case "hotkeys":return (<div className="space-y-6">+ {isUsingHyprland && hyprlandConfigStatus && !hyprlandConfigStatus.canWrite && (+ <Alert>+ <Info className="h-4 w-4" />+ <AlertTitle>+ {t("settingsPage.general.hotkey.hyprlandConfigWriteWarningTitle")}+ </AlertTitle>+ <AlertDescription>+ {t("settingsPage.general.hotkey.hyprlandConfigWriteWarningDescription", {+ path: hyprlandConfigStatus.path,+ })}+ </AlertDescription>+ </Alert>+ )}{/* Dictation Hotkey */}<div><SectionHeadertitle={t("settingsPage.general.hotkey.title")}description={t("settingsPage.general.hotkey.description")}+ note={isUsingHyprland && t("settingsPage.general.hotkey.hyprlandUnbindDescription")}/><SettingsPanel><SettingsPanelRow>diff --git a/src/helpers/hotkeyManager.js b/src/helpers/hotkeyManager.jsindex 53a74f927..b442e90d4 100644--- a/src/helpers/hotkeyManager.js+++ b/src/helpers/hotkeyManager.js@@ -1190,6 +1190,11 @@ class HotkeyManager extends EventEmitter {return this.useHyprland;}+ getHyprlandConfigStatus() {+ if (!this.hyprlandManager) return null;+ return HyprlandShortcutManager.getHyprlandConfigStatus();+ }+isUsingKDE() {return this.useKDE;}diff --git a/src/helpers/hyprlandShortcut.js b/src/helpers/hyprlandShortcut.jsindex 90f95d9ba..89c1d249d 100644--- a/src/helpers/hyprlandShortcut.js+++ b/src/helpers/hyprlandShortcut.js@@ -1,4 +1,7 @@const { execFileSync } = require("child_process");+const fs = require("fs");+const path = require("path");+const os = require("os");const debugLogger = require("./debugLogger");const DBUS_SERVICE_NAME = "com.openwhispr.App";@@ -42,6 +45,40 @@ const ELECTRON_TO_HYPRLAND_KEY = {const VALID_HOTKEY_PATTERN =/^((CommandOrControl|CmdOrCtrl|Control|Ctrl|Alt|Option|Shift|Super|Meta|Win|Command|Cmd)(\+(CommandOrControl|CmdOrCtrl|Control|Ctrl|Alt|Option|Shift|Super|Meta|Win|Command|Cmd))*(\+)?)?(F([1-9]|1[0-9]|2[0-4])|[A-Za-z0-9]|Space|Escape|Tab|Backspace|Delete|Insert|Home|End|PageUp|PageDown|ArrowUp|ArrowDown|ArrowLeft|ArrowRight|Enter|PrintScreen|ScrollLock|Pause|Backquote|`)?$/i;+const BINDS_FILENAME = "openwhispr-binds.conf";+const MANAGED_HEADER_LINES = [+ "# OpenWhispr keybinds (managed automatically)",+ "# If you delete this file, also remove the matching source line from your Hyprland config.",+];++function isManagedHeaderLine(line) {+ return MANAGED_HEADER_LINES.includes(line.trim());+}++function buildManagedBindsContent(lines = []) {+ const body = lines.join("\n").trim();+ return MANAGED_HEADER_LINES.join("\n") + "\n" + (body ? body + "\n" : "");+}++function getHyprConfigDir() {+ if (process.env.HYPRLAND_CONFIG) {+ return path.dirname(path.resolve(process.env.HYPRLAND_CONFIG));+ }+ const xdgConfigHome = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");+ return path.join(xdgConfigHome, "hypr");+}++function getHyprlandConfPath() {+ if (process.env.HYPRLAND_CONFIG) {+ return path.resolve(process.env.HYPRLAND_CONFIG);+ }+ return path.join(getHyprConfigDir(), "hyprland.conf");+}++function getBindsFilePath() {+ return path.join(getHyprConfigDir(), BINDS_FILENAME);+}+let dbus = null;function getDBus() {@@ -231,9 +268,95 @@ class HyprlandShortcutManager {};}+ _writeBindToConfig(bindLine) {+ const bindsFile = getBindsFilePath();+ fs.mkdirSync(path.dirname(bindsFile), { recursive: true });++ let content = "";+ try {+ content = fs.readFileSync(bindsFile, "utf-8");+ } catch (err) {+ if (err.code !== "ENOENT") throw err;+ }++ const lines = content.split("\n").filter((line) => {+ const trimmed = line.trim();+ if (!trimmed || isManagedHeaderLine(trimmed)) return false;+ if (trimmed.startsWith("#")) return true;+ return !trimmed.includes(DBUS_SERVICE_NAME);+ });++ const newContent = buildManagedBindsContent([...lines, bindLine]);++ fs.writeFileSync(bindsFile, newContent, "utf-8");+ }++ _removeBindFromConfig() {+ const bindsFile = getBindsFilePath();+ let content = "";+ try {+ content = fs.readFileSync(bindsFile, "utf-8");+ } catch (err) {+ if (err.code === "ENOENT") return;+ throw err;+ }++ const lines = content.split("\n").filter((line) => {+ const trimmed = line.trim();+ if (!trimmed || isManagedHeaderLine(trimmed)) return false;+ if (trimmed.startsWith("#")) return true;+ return !trimmed.includes(DBUS_SERVICE_NAME);+ });++ fs.writeFileSync(bindsFile, buildManagedBindsContent(lines), "utf-8");+ }++ _ensureSourceInMainConfig() {+ const mainConfig = getHyprlandConfPath();+ let content;+ try {+ content = fs.readFileSync(mainConfig, "utf-8");+ } catch (err) {+ if (err.code === "ENOENT") return;+ throw err;+ }++ const sourceLine = `source = ./${BINDS_FILENAME}`;+ if (content.includes(`./${BINDS_FILENAME}`)) return;++ const separator = content.length > 0 && !content.endsWith("\n") ? "\n" : "";+ fs.appendFileSync(mainConfig, `${separator}${sourceLine}\n`, "utf-8");+ debugLogger.log("[HyprlandShortcut] Added source directive to hyprland.conf");+ }++ static getHyprlandConfigStatus() {+ const mainConfig = getHyprlandConfPath();+ const status = {+ path: mainConfig,+ canWrite: false,+ };++ try {+ fs.accessSync(mainConfig, fs.constants.F_OK);+ try {+ fs.accessSync(mainConfig, fs.constants.W_OK);+ status.canWrite = true;+ } catch {+ debugLogger.log("[HyprlandShortcut] Hyprland config is not writable:", mainConfig);+ }+ } catch {+ debugLogger.log("[HyprlandShortcut] Hyprland config not found:", mainConfig);+ }++ return status;+ }+/*** Register a keybinding in Hyprland using hyprctl keyword bind.* The binding executes a dbus-send command that calls our Toggle() method.+ *+ * Also writes the bind to openwhispr-binds.conf (sourced from hyprland.conf)+ * so it survives `hyprctl reload`.*/async registerKeybinding(hotkey) {if (!HyprlandShortcutManager.isHyprland()) {@@ -253,8 +376,8 @@ class HyprlandShortcutManager {}try {- // First unregister any existing binding- if (this.currentBinding) {+ // First unregister any existing OpenWhispr binding if the hotkey changed.+ if (this.currentBinding && this.currentBinding !== converted.bindKey) {await this.unregisterKeybinding();}@@ -263,6 +386,18 @@ class HyprlandShortcutManager {// hyprctl keyword bind "MODS, key, exec, command"const bindValue = `${converted.bindKey}, exec, ${dbusCommand}`;+ try {+ execFileSync("hyprctl", ["keyword", "unbind", converted.bindKey], {+ stdio: "pipe",+ timeout: 5000,+ });+ } catch (err) {+ debugLogger.log(+ `[HyprlandShortcut] Pre-bind unbind for "${converted.bindKey}" failed, continuing:`,+ err.message+ );+ }+execFileSync("hyprctl", ["keyword", "bind", bindValue], {stdio: "pipe",timeout: 5000,@@ -270,6 +405,17 @@ class HyprlandShortcutManager {this.currentBinding = converted.bindKey;this.isRegistered = true;++ try {+ this._writeBindToConfig(`bind = ${bindValue}`);+ this._ensureSourceInMainConfig();+ } catch (err) {+ debugLogger.log(+ "[HyprlandShortcut] Failed to persist keybinding; runtime bind is still active:",+ err.message+ );+ }+debugLogger.log(`[HyprlandShortcut] Keybinding "${hotkey}" (${converted.bindKey}) registered successfully`);@@ -297,25 +443,27 @@ class HyprlandShortcutManager {return true;}+ const binding = this.currentBinding;+try {- execFileSync("hyprctl", ["keyword", "unbind", this.currentBinding], {+ execFileSync("hyprctl", ["keyword", "unbind", binding], {stdio: "pipe",timeout: 5000,});+ } catch (err) {+ debugLogger.log(`[HyprlandShortcut] Runtime unbind for "${binding}" failed:`, err.message);+ }- debugLogger.log(- `[HyprlandShortcut] Keybinding "${this.currentBinding}" unregistered successfully`- );- this.currentBinding = null;- this.isRegistered = false;- return true;+ try {+ this._removeBindFromConfig();} catch (err) {- debugLogger.log("[HyprlandShortcut] Failed to unregister keybinding:", err.message);- // Even if unbind fails, clear state so we don't keep retrying- this.currentBinding = null;- this.isRegistered = false;- return false;+ debugLogger.log("[HyprlandShortcut] Failed to remove persisted keybinding:", err.message);}++ debugLogger.log(`[HyprlandShortcut] Keybinding "${binding}" unregistered successfully`);+ this.currentBinding = null;+ this.isRegistered = false;+ return true;}/**diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex d4ae45848..fdb9c1dc2 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -2382,6 +2382,11 @@ class IPCHandlers {};});+ ipcMain.handle("get-hyprland-config-status", async () => {+ if (!this.windowManager.isUsingHyprlandHotkeys()) return null;+ return this.windowManager.getHyprlandConfigStatus();+ });+ipcMain.handle("register-cancel-hotkey", async (event, key) => {const hotkeyManager = this.windowManager.hotkeyManager;const mainWindow = this.windowManager.mainWindow;diff --git a/src/helpers/windowManager.js b/src/helpers/windowManager.jsindex 9aec9d1c9..9f4e69373 100644--- a/src/helpers/windowManager.js+++ b/src/helpers/windowManager.js@@ -532,6 +532,10 @@ class WindowManager {return this.hotkeyManager.isUsingHyprland();}+ getHyprlandConfigStatus() {+ return this.hotkeyManager.getHyprlandConfigStatus();+ }+isUsingKDEHotkeys() {return this.hotkeyManager.isUsingKDE();}diff --git a/src/hooks/useHotkeyModeInfo.ts b/src/hooks/useHotkeyModeInfo.tsnew file mode 100644index 000000000..c53c5b876--- /dev/null+++ b/src/hooks/useHotkeyModeInfo.ts@@ -0,0 +1,58 @@+import { useEffect, useState } from "react";+import logger from "../utils/logger";++export interface HyprlandConfigStatus {+ canWrite: boolean;+ path: string;+}++export interface HotkeyModeInfo {+ isUsingNativeShortcut: boolean;+ isUsingHyprland: boolean;+ supportsPushToTalk: boolean;+ hyprlandConfigStatus: HyprlandConfigStatus | null;+}++const DEFAULT_INFO: HotkeyModeInfo = {+ isUsingNativeShortcut: false,+ isUsingHyprland: false,+ supportsPushToTalk: true,+ hyprlandConfigStatus: null,+};++/**+ * Resolves how the dictation hotkey is registered for the current session+ * (native shortcut, Hyprland) and, on Hyprland, whether its config is+ * persistable. `scope` tags log output for the calling surface.+ */+export function useHotkeyModeInfo(scope: string): HotkeyModeInfo {+ const [modeInfo, setModeInfo] = useState<HotkeyModeInfo>(DEFAULT_INFO);++ useEffect(() => {+ let cancelled = false;+ const checkHotkeyMode = async () => {+ try {+ const info = await window.electronAPI?.getHotkeyModeInfo?.();+ if (!info || cancelled) return;+ const hyprlandConfigStatus = info.isUsingHyprland+ ? ((await window.electronAPI?.getHyprlandConfigStatus?.()) ?? null)+ : null;+ if (cancelled) return;+ setModeInfo({+ isUsingNativeShortcut: info.isUsingNativeShortcut,+ isUsingHyprland: info.isUsingHyprland,+ supportsPushToTalk: info.supportsPushToTalk,+ hyprlandConfigStatus,+ });+ } catch (error) {+ logger.error("Failed to check hotkey mode", { error }, scope);+ }+ };+ checkHotkeyMode();+ return () => {+ cancelled = true;+ };+ }, [scope]);++ return modeInfo;+}diff --git a/src/locales/en/translation.json b/src/locales/en/translation.jsonindex ee2cd0fa7..5fd36fac5 100644--- a/src/locales/en/translation.json+++ b/src/locales/en/translation.json@@ -1479,7 +1479,10 @@"linuxPttPermissionDescription": "Run this command and log out/in: sudo usermod -aG input $USER","linuxPttSetupTitle": "Hold to Speak needs setup","linuxPttSetupDescription": "Your user needs access to keyboard input devices.",- "linuxPttSetupNote": "After running the command, log out and log back in."+ "linuxPttSetupNote": "After running the command, log out and log back in.",+ "hyprlandConfigWriteWarningTitle": "Hyprland keybinds will not persist",+ "hyprlandConfigWriteWarningDescription": "OpenWhispr cannot write to {{path}}, so keybinds will not survive a Hyprland config reload. Make sure the file exists and is writable.",+ "hyprlandUnbindDescription": "On Hyprland, OpenWhispr claims the selected shortcut. Any existing Hyprland bind that uses the same key combination will be unbound when OpenWhispr registers its shortcut."},"meetingHotkey": {"title": "Meeting Mode Hotkey",diff --git a/src/types/electron.ts b/src/types/electron.tsindex ebea0768c..4039c2f3d 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -917,6 +917,7 @@ declare global {isUsingNativeShortcut: boolean;supportsPushToTalk: boolean;}>;+ getHyprlandConfigStatus?: () => Promise<{ canWrite: boolean; path: string } | null>;// Wayland paste diagnosticsgetYdotoolStatus?: () => Promise<{