Skip to content

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

refactor: improve mic permission flow by removing blocking enumerateDevices check

Gabriel Stein165bf19d73e2
diff --git a/src/components/OnboardingFlow.tsx b/src/components/OnboardingFlow.tsx
index 177a47ebb..17dfa8c71 100644
--- a/src/components/OnboardingFlow.tsx
+++ b/src/components/OnboardingFlow.tsx
@@ -24,6 +24,7 @@ import WhisperModelPicker from "./WhisperModelPicker";
import ProcessingModeSelector from "./ui/ProcessingModeSelector";
import ApiKeyInput from "./ui/ApiKeyInput";
import PermissionCard from "./ui/PermissionCard";
+import MicPermissionWarning from "./ui/MicPermissionWarning";
import StepProgress from "./ui/StepProgress";
import { AlertDialog, ConfirmDialog } from "./ui/dialog";
import { useLocalStorage } from "../hooks/useLocalStorage";
@@ -858,28 +859,11 @@ export default function OnboardingFlow({ onComplete }: OnboardingFlowProps) {
/>
{!permissionsHook.micPermissionGranted && (
- <div className="rounded-lg border border-amber-200 bg-amber-50 p-4 space-y-3">
- <p className="text-sm text-amber-900">
- {permissionsHook.micPermissionError ||
- "If the prompt doesn’t appear, open Sound settings, select your microphone, then try Grant Access again."}
- </p>
- <div className="flex flex-wrap gap-2">
- <Button
- variant="outline"
- size="sm"
- onClick={permissionsHook.openSoundInputSettings}
- >
- Open Sound Input Settings
- </Button>
- <Button
- variant="outline"
- size="sm"
- onClick={permissionsHook.openMicPrivacySettings}
- >
- Open Microphone Privacy
- </Button>
- </div>
- </div>
+ <MicPermissionWarning
+ error={permissionsHook.micPermissionError}
+ onOpenSoundSettings={permissionsHook.openSoundInputSettings}
+ onOpenPrivacySettings={permissionsHook.openMicPrivacySettings}
+ />
)}
<PermissionCard
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index f23573169..81f8d1fa9 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -12,6 +12,7 @@ import { useAgentName } from "../utils/agentName";
import { useWhisper } from "../hooks/useWhisper";
import { usePermissions } from "../hooks/usePermissions";
import { useClipboard } from "../hooks/useClipboard";
+import MicPermissionWarning from "./ui/MicPermissionWarning";
import { REASONING_PROVIDERS } from "../utils/languages";
import { formatHotkeyLabel } from "../utils/hotkeys";
import LanguageSelector from "./ui/LanguageSelector";
@@ -800,28 +801,11 @@ export default function SettingsPage({
Fix Permission Issues
</Button>
{!permissionsHook.micPermissionGranted && (
- <div className="rounded-lg border border-amber-200 bg-amber-50 p-4 space-y-3">
- <p className="text-sm text-amber-900">
- {permissionsHook.micPermissionError ||
- "If macOS never shows the microphone prompt, open Sound settings, pick your microphone, then try the test again."}
- </p>
- <div className="flex flex-wrap gap-2">
- <Button
- variant="outline"
- size="sm"
- onClick={permissionsHook.openSoundInputSettings}
- >
- Open Sound Input Settings
- </Button>
- <Button
- variant="outline"
- size="sm"
- onClick={permissionsHook.openMicPrivacySettings}
- >
- Open Microphone Privacy
- </Button>
- </div>
- </div>
+ <MicPermissionWarning
+ error={permissionsHook.micPermissionError}
+ onOpenSoundSettings={permissionsHook.openSoundInputSettings}
+ onOpenPrivacySettings={permissionsHook.openMicPrivacySettings}
+ />
)}
</div>
</div>
diff --git a/src/components/ui/MicPermissionWarning.tsx b/src/components/ui/MicPermissionWarning.tsx
new file mode 100644
index 000000000..28d6af733
--- /dev/null
+++ b/src/components/ui/MicPermissionWarning.tsx
@@ -0,0 +1,60 @@
+import { useMemo } from "react";
+import { Button } from "./button";
+
+interface MicPermissionWarningProps {
+ error: string | null;
+ onOpenSoundSettings: () => void;
+ onOpenPrivacySettings: () => void;
+}
+
+const getPlatformInfo = () => {
+ if (typeof navigator === "undefined") {
+ return { isMac: true, isWindows: false, isLinux: false };
+ }
+ const ua = navigator.userAgent.toLowerCase();
+ return {
+ isMac: ua.includes("mac"),
+ isWindows: ua.includes("win"),
+ isLinux: ua.includes("linux"),
+ };
+};
+
+export default function MicPermissionWarning({
+ error,
+ onOpenSoundSettings,
+ onOpenPrivacySettings,
+}: MicPermissionWarningProps) {
+ const { isMac, isWindows, isLinux } = useMemo(() => getPlatformInfo(), []);
+
+ const defaultMessage = isWindows
+ ? "If the microphone prompt doesn't appear, open Windows Settings to select your input device, then try again."
+ : isLinux
+ ? "If the microphone prompt doesn't appear, open your system sound settings to select your input device, then try again."
+ : "If the microphone prompt doesn't appear, open Sound settings to select your input device, then try again.";
+
+ const soundButtonLabel = isWindows
+ ? "Open Sound Settings"
+ : isLinux
+ ? "Open Sound Settings"
+ : "Open Sound Input Settings";
+
+ const privacyButtonLabel = isWindows
+ ? "Open Privacy Settings"
+ : isLinux
+ ? "Open Privacy Settings"
+ : "Open Microphone Privacy";
+
+ return (
+ <div className="rounded-lg border border-amber-200 bg-amber-50 p-4 space-y-3">
+ <p className="text-sm text-amber-900">{error || defaultMessage}</p>
+ <div className="flex flex-wrap gap-2">
+ <Button variant="outline" size="sm" onClick={onOpenSoundSettings}>
+ {soundButtonLabel}
+ </Button>
+ <Button variant="outline" size="sm" onClick={onOpenPrivacySettings}>
+ {privacyButtonLabel}
+ </Button>
+ </div>
+ </div>
+ );
+}
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index 8ed86e123..def2a0745 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -4,33 +4,41 @@ const AppUtils = require("../utils");
const debugLogger = require("./debugLogger");
const runDetachedCommand = (command, args = []) => {
- try {
- const child = spawn(command, args, {
- detached: true,
- stdio: "ignore",
- });
- if (typeof child.unref === "function") {
- child.unref();
+ return new Promise((resolve) => {
+ try {
+ const child = spawn(command, args, {
+ detached: true,
+ stdio: "ignore",
+ });
+ child.on("error", (error) => {
+ debugLogger.error(`Failed to run ${command}`, error);
+ resolve(false);
+ });
+ child.on("spawn", () => {
+ if (typeof child.unref === "function") {
+ child.unref();
+ }
+ resolve(true);
+ });
+ } catch (error) {
+ debugLogger.error(`Failed to spawn ${command}`, error);
+ resolve(false);
}
- return true;
- } catch (error) {
- debugLogger.error(`Failed to run ${command}`, error);
- return false;
- }
+ });
};
-const openMacPreference = (urls = []) => {
+const openMacPreference = async (urls = []) => {
for (const url of urls) {
- if (runDetachedCommand("open", [url])) {
+ if (await runDetachedCommand("open", [url])) {
return true;
}
}
return runDetachedCommand("open", ["-a", "System Settings"]);
};
-const openLinuxSettings = (commands = []) => {
+const openLinuxSettings = async (commands = []) => {
for (const [command, args] of commands) {
- if (runDetachedCommand(command, args)) {
+ if (await runDetachedCommand(command, args)) {
return true;
}
}
@@ -576,7 +584,7 @@ class IPCHandlers {
});
}
- openPlatformSettings(target) {
+ async openPlatformSettings(target) {
if (process.platform === "darwin") {
const urls =
target === "microphone"
@@ -588,8 +596,8 @@ class IPCHandlers {
"x-apple.systempreferences:com.apple.preference.sound?input",
"x-apple.systempreferences:com.apple.preference.sound",
];
- openMacPreference(urls);
- return { success: true };
+ const opened = await openMacPreference(urls);
+ return { success: opened };
}
if (process.platform === "win32") {
@@ -598,7 +606,7 @@ class IPCHandlers {
? "ms-settings:privacy-microphone"
: "ms-settings:sound";
try {
- shell.openExternal(uri);
+ await shell.openExternal(uri);
return { success: true };
} catch (error) {
debugLogger.error("Failed to open Windows settings", error);
@@ -609,15 +617,15 @@ class IPCHandlers {
const linuxCommands =
target === "microphone"
? [
- ["xdg-open", ["gnome-control-center", "privacy"]],
["gnome-control-center", ["privacy"]],
+ ["kde-open5", ["kcm_users"]],
]
: [
- ["xdg-open", ["gnome-control-center", "sound"]],
["gnome-control-center", ["sound"]],
+ ["kde-open5", ["kcm_pulseaudio"]],
];
- if (openLinuxSettings(linuxCommands)) {
+ if (await openLinuxSettings(linuxCommands)) {
return { success: true };
}
diff --git a/src/hooks/usePermissions.ts b/src/hooks/usePermissions.ts
index 77027cb55..567c611a7 100644
--- a/src/hooks/usePermissions.ts
+++ b/src/hooks/usePermissions.ts
@@ -18,42 +18,60 @@ export interface UsePermissionsProps {
showAlertDialog: (dialog: { title: string; description?: string }) => void;
}
-const DEFAULT_MIC_MESSAGE =
- "If nothing pops up, open System Settings → Sound → Input, choose your microphone, then click Grant Access again.";
-
const stopTracks = (stream?: MediaStream) => {
try {
stream?.getTracks?.().forEach((track) => track.stop());
- } catch (error) {
+ } catch {
// ignore track cleanup errors
}
};
-const describeMicError = (error: any): string => {
- if (!error) {
- return DEFAULT_MIC_MESSAGE;
+const getPlatformSettingsPath = (): string => {
+ if (typeof navigator !== "undefined") {
+ const ua = navigator.userAgent.toLowerCase();
+ if (ua.includes("win")) return "Settings → Privacy → Microphone";
+ if (ua.includes("linux")) return "your system sound settings";
+ }
+ return "System Settings → Sound → Input";
+};
+
+const getPlatformPrivacyPath = (): string => {
+ if (typeof navigator !== "undefined") {
+ const ua = navigator.userAgent.toLowerCase();
+ if (ua.includes("win")) return "Settings → Privacy → Microphone";
+ if (ua.includes("linux")) return "your system privacy settings";
+ }
+ return "System Settings → Privacy & Security → Microphone";
+};
+
+const describeMicError = (error: unknown): string => {
+ if (!error || typeof error !== "object") {
+ return "Microphone access failed. Please try again.";
}
- const name = error?.name || "";
- const message = (error?.message || "").toLowerCase();
+ const err = error as { name?: string; message?: string };
+ const name = err.name || "";
+ const message = (err.message || "").toLowerCase();
+ const settingsPath = getPlatformSettingsPath();
+ const privacyPath = getPlatformPrivacyPath();
if (name === "NotFoundError") {
- return "No microphones were detected. Connect or select a microphone in System Settings → Sound → Input.";
+ return `No microphones were detected. Connect or select a microphone in ${settingsPath}.`;
}
if (name === "NotAllowedError" || name === "SecurityError") {
- return "Permission was denied. Open System Settings → Privacy & Security → Microphone and allow OpenWhispr.";
+ return `Permission was denied. Open ${privacyPath} and allow OpenWhispr.`;
}
if (name === "NotReadableError" || name === "AbortError") {
- return "macOS could not start the selected microphone. Choose an input device in System Settings → Sound → Input, then rerun the test.";
+ return `Could not start the selected microphone. Choose an input device in ${settingsPath}, then rerun the test.`;
}
if (message.includes("no audio input") || message.includes("not available")) {
- return "No active audio input was found. Pick a microphone in System Settings → Sound → Input.";
+ return `No active audio input was found. Pick a microphone in ${settingsPath}.`;
}
- return `Microphone access failed: ${error?.message || "Unknown error"}. Select a different input device and try again.`;
+ return `Microphone access failed: ${err.message || "Unknown error"}. Select a different input device and try again.`;
};
export const usePermissions = (
@@ -104,27 +122,6 @@ export const usePermissions = (
setMicPermissionError(null);
try {
- if (typeof navigator.mediaDevices.enumerateDevices === "function") {
- const devices = await navigator.mediaDevices.enumerateDevices();
- const audioInputs = devices.filter(
- (device) => device.kind === "audioinput"
- );
- if (audioInputs.length === 0) {
- const message =
- "No microphones were found. Connect or select a microphone in System Settings → Sound → Input.";
- setMicPermissionError(message);
- if (showAlertDialog) {
- showAlertDialog({
- title: "No Microphone Detected",
- description: message,
- });
- } else {
- alert(message);
- }
- return;
- }
- }
-
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
stopTracks(stream);
setMicPermissionGranted(true);