Skip to content

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

fix: resolve macOS hardened-runtime mic permission prompt via main-process IPC and unify API key cache invalidation with event-based AudioManager sync

Gabriel Steind11b9b7042b9
diff --git a/preload.js b/preload.js
index 36717eb77..629dbb4a0 100644
--- a/preload.js
+++ b/preload.js
@@ -237,6 +237,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
openLogsFolder: () => ipcRenderer.invoke("open-logs-folder"),
// System settings helpers for microphone/audio permissions
+ requestMicrophoneAccess: () => ipcRenderer.invoke("request-microphone-access"),
openMicrophoneSettings: () => ipcRenderer.invoke("open-microphone-settings"),
openSoundInputSettings: () => ipcRenderer.invoke("open-sound-input-settings"),
openAccessibilitySettings: () => ipcRenderer.invoke("open-accessibility-settings"),
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.js
index 621e7bcf6..94e364e24 100644
--- a/src/helpers/audioManager.js
+++ b/src/helpers/audioManager.js
@@ -32,6 +32,12 @@ class AudioManager {
this.onPartialTranscript = null;
this.cachedApiKey = null;
this.cachedApiKeyProvider = null;
+
+ this._onApiKeyChanged = () => {
+ this.cachedApiKey = null;
+ this.cachedApiKeyProvider = null;
+ };
+ window.addEventListener("api-key-changed", this._onApiKeyChanged);
this.cachedTranscriptionEndpoint = null;
this.cachedEndpointProvider = null;
this.cachedEndpointBaseUrl = null;
@@ -2104,6 +2110,9 @@ class AudioManager {
this.onError = null;
this.onTranscriptionComplete = null;
this.onPartialTranscript = null;
+ if (this._onApiKeyChanged) {
+ window.removeEventListener("api-key-changed", this._onApiKeyChanged);
+ }
}
}
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index a43b41305..cdb68f539 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -976,6 +976,15 @@ class IPCHandlers {
ipcMain.handle("open-sound-input-settings", () => openSystemSettings("sound"));
ipcMain.handle("open-accessibility-settings", () => openSystemSettings("accessibility"));
+ ipcMain.handle("request-microphone-access", async () => {
+ if (process.platform !== "darwin") {
+ return { granted: true };
+ }
+ const { systemPreferences } = require("electron");
+ const granted = await systemPreferences.askForMediaAccess("microphone");
+ return { granted };
+ });
+
// Auth: clear all session cookies for sign-out.
// This clears every cookie in the renderer session rather than targeting
// individual auth cookies, which is acceptable because the app only sets
diff --git a/src/hooks/usePermissions.ts b/src/hooks/usePermissions.ts
index 4f8c9f81c..e98f60696 100644
--- a/src/hooks/usePermissions.ts
+++ b/src/hooks/usePermissions.ts
@@ -180,6 +180,15 @@ export const usePermissions = (
setMicPermissionError(null);
try {
+ // macOS hardened runtime requires main-process mic prompt before getUserMedia works
+ if (window.electronAPI?.requestMicrophoneAccess) {
+ try {
+ await window.electronAPI.requestMicrophoneAccess();
+ } catch {
+ // ignored — getUserMedia below will surface the error
+ }
+ }
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
stopTracks(stream);
setMicPermissionGranted(true);
diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts
index 58ab971cc..97e089b33 100644
--- a/src/hooks/useSettings.ts
+++ b/src/hooks/useSettings.ts
@@ -370,82 +370,82 @@ export function useSettings() {
}
}, 1000);
- // Wrapped setters that sync to Electron IPC and invalidate cache
+ const invalidateApiKeyCaches = useCallback(
+ (provider?: "openai" | "anthropic" | "gemini" | "groq" | "custom") => {
+ if (provider) {
+ ReasoningService.clearApiKeyCache(provider);
+ }
+ window.dispatchEvent(new Event("api-key-changed"));
+ debouncedPersistToEnv();
+ },
+ [debouncedPersistToEnv]
+ );
+
const setOpenaiApiKey = useCallback(
(key: string) => {
setOpenaiApiKeyLocal(key);
window.electronAPI?.saveOpenAIKey?.(key);
- ReasoningService.clearApiKeyCache("openai");
- debouncedPersistToEnv();
+ invalidateApiKeyCaches("openai");
},
- [setOpenaiApiKeyLocal, debouncedPersistToEnv]
+ [setOpenaiApiKeyLocal, invalidateApiKeyCaches]
);
const setAnthropicApiKey = useCallback(
(key: string) => {
setAnthropicApiKeyLocal(key);
window.electronAPI?.saveAnthropicKey?.(key);
- ReasoningService.clearApiKeyCache("anthropic");
- debouncedPersistToEnv();
+ invalidateApiKeyCaches("anthropic");
},
- [setAnthropicApiKeyLocal, debouncedPersistToEnv]
+ [setAnthropicApiKeyLocal, invalidateApiKeyCaches]
);
const setGeminiApiKey = useCallback(
(key: string) => {
setGeminiApiKeyLocal(key);
window.electronAPI?.saveGeminiKey?.(key);
- ReasoningService.clearApiKeyCache("gemini");
- debouncedPersistToEnv();
+ invalidateApiKeyCaches("gemini");
},
- [setGeminiApiKeyLocal, debouncedPersistToEnv]
+ [setGeminiApiKeyLocal, invalidateApiKeyCaches]
);
const setGroqApiKey = useCallback(
(key: string) => {
setGroqApiKeyLocal(key);
window.electronAPI?.saveGroqKey?.(key);
- ReasoningService.clearApiKeyCache("groq");
- debouncedPersistToEnv();
+ invalidateApiKeyCaches("groq");
},
- [setGroqApiKeyLocal, debouncedPersistToEnv]
+ [setGroqApiKeyLocal, invalidateApiKeyCaches]
);
const setCustomTranscriptionApiKey = useCallback(
(key: string) => {
setCustomTranscriptionApiKeyLocal(key);
window.electronAPI?.saveCustomTranscriptionKey?.(key);
- debouncedPersistToEnv();
+ invalidateApiKeyCaches();
},
- [setCustomTranscriptionApiKeyLocal, debouncedPersistToEnv]
+ [setCustomTranscriptionApiKeyLocal, invalidateApiKeyCaches]
);
const setCustomReasoningApiKey = useCallback(
(key: string) => {
setCustomReasoningApiKeyLocal(key);
window.electronAPI?.saveCustomReasoningKey?.(key);
- ReasoningService.clearApiKeyCache("custom");
- debouncedPersistToEnv();
+ invalidateApiKeyCaches("custom");
},
- [setCustomReasoningApiKeyLocal, debouncedPersistToEnv]
+ [setCustomReasoningApiKeyLocal, invalidateApiKeyCaches]
);
- // Hotkey
const [dictationKey, setDictationKeyLocal] = useLocalStorage("dictationKey", "", {
serialize: String,
deserialize: String,
});
- // Wrap setDictationKey to notify main process (for Windows Push-to-Talk)
- // and persist to file-based storage for reliable startup
const setDictationKey = useCallback(
(key: string) => {
setDictationKeyLocal(key);
- // Notify main process so Windows key listener can restart with new key
if (typeof window !== "undefined" && window.electronAPI?.notifyHotkeyChanged) {
window.electronAPI.notifyHotkeyChanged(key);
}
- // Also save to file-based storage for reliable persistence across restarts
if (typeof window !== "undefined" && window.electronAPI?.saveDictationKey) {
window.electronAPI.saveDictationKey(key);
}
diff --git a/src/types/electron.ts b/src/types/electron.ts
index 090e6e1d8..48ed531cb 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -398,6 +398,7 @@ declare global {
getAudioDiagnostics: () => Promise<AudioDiagnosticsResult>;
// System settings helpers
+ requestMicrophoneAccess?: () => Promise<{ granted: boolean }>;
openMicrophoneSettings?: () => Promise<{ success: boolean; error?: string }>;
openSoundInputSettings?: () => Promise<{ success: boolean; error?: string }>;
openAccessibilitySettings?: () => Promise<{ success: boolean; error?: string }>;