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: persist custom endpoint API keys to .env file
Gabriel Stein3caf625261a7
diff --git a/preload.js b/preload.jsindex bdf08fa0a..b507dd823 100644--- a/preload.js+++ b/preload.js@@ -160,6 +160,12 @@ contextBridge.exposeInMainWorld("electronAPI", {getGroqKey: () => ipcRenderer.invoke("get-groq-key"),saveGroqKey: (key) => ipcRenderer.invoke("save-groq-key", key),+ // Custom endpoint API keys+ getCustomTranscriptionKey: () => ipcRenderer.invoke("get-custom-transcription-key"),+ saveCustomTranscriptionKey: (key) => ipcRenderer.invoke("save-custom-transcription-key", key),+ getCustomReasoningKey: () => ipcRenderer.invoke("get-custom-reasoning-key"),+ saveCustomReasoningKey: (key) => ipcRenderer.invoke("save-custom-reasoning-key", key),+saveAllKeysToEnv: () => ipcRenderer.invoke("save-all-keys-to-env"),// Local reasoningdiff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex aa3c24770..11f28527b 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -329,8 +329,19 @@ class AudioManager {let apiKey = null;if (provider === "custom") {- apiKey = localStorage.getItem("customTranscriptionApiKey") || "";- apiKey = apiKey.trim();+ try {+ apiKey = await window.electronAPI.getCustomTranscriptionKey?.();+ } catch (err) {+ logger.debug(+ "Failed to get custom transcription key via IPC, falling back to localStorage",+ { error: err?.message },+ "transcription"+ );+ }+ if (!apiKey || !apiKey.trim()) {+ apiKey = localStorage.getItem("customTranscriptionApiKey") || "";+ }+ apiKey = apiKey?.trim() || "";logger.debug("Custom STT API key retrieval",@@ -343,6 +354,7 @@ class AudioManager {"transcription");+ // For custom, we allow null/empty - the endpoint may not require authif (!apiKey) {apiKey = null;}diff --git a/src/helpers/environment.js b/src/helpers/environment.jsindex 293547ff1..eea5e8c0a 100644--- a/src/helpers/environment.js+++ b/src/helpers/environment.js@@ -75,6 +75,22 @@ class EnvironmentManager {return this._saveKey("GROQ_API_KEY", key);}+ getCustomTranscriptionKey() {+ return this._getKey("CUSTOM_TRANSCRIPTION_API_KEY");+ }++ saveCustomTranscriptionKey(key) {+ return this._saveKey("CUSTOM_TRANSCRIPTION_API_KEY", key);+ }++ getCustomReasoningKey() {+ return this._getKey("CUSTOM_REASONING_API_KEY");+ }++ saveCustomReasoningKey(key) {+ return this._saveKey("CUSTOM_REASONING_API_KEY", key);+ }+createProductionEnvFile(apiKey) {const envPath = path.join(app.getPath("userData"), ".env");@@ -110,6 +126,12 @@ OPENAI_API_KEY=${apiKey}if (process.env.GROQ_API_KEY) {envContent += `GROQ_API_KEY=${process.env.GROQ_API_KEY}\n`;}+ if (process.env.CUSTOM_TRANSCRIPTION_API_KEY) {+ envContent += `CUSTOM_TRANSCRIPTION_API_KEY=${process.env.CUSTOM_TRANSCRIPTION_API_KEY}\n`;+ }+ if (process.env.CUSTOM_REASONING_API_KEY) {+ envContent += `CUSTOM_REASONING_API_KEY=${process.env.CUSTOM_REASONING_API_KEY}\n`;+ }fs.writeFileSync(envPath, envContent, "utf8");diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex 3da782240..da2f7d218 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -444,6 +444,22 @@ class IPCHandlers {return this.environmentManager.saveGroqKey(key);});+ ipcMain.handle("get-custom-transcription-key", async () => {+ return this.environmentManager.getCustomTranscriptionKey();+ });++ ipcMain.handle("save-custom-transcription-key", async (event, key) => {+ return this.environmentManager.saveCustomTranscriptionKey(key);+ });++ ipcMain.handle("get-custom-reasoning-key", async () => {+ return this.environmentManager.getCustomReasoningKey();+ });++ ipcMain.handle("save-custom-reasoning-key", async (event, key) => {+ return this.environmentManager.saveCustomReasoningKey(key);+ });+ipcMain.handle("save-anthropic-key", async (event, key) => {return this.environmentManager.saveAnthropicKey(key);});diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.tsindex 5a8c9d308..263012b82 100644--- a/src/hooks/useSettings.ts+++ b/src/hooks/useSettings.ts@@ -150,8 +150,8 @@ export function useSettings() {deserialize: String,});- // Custom endpoint API keys (not synced to .env - stored in localStorage only)- const [customTranscriptionApiKey, setCustomTranscriptionApiKey] = useLocalStorage(+ // Custom endpoint API keys - synced to .env like other keys+ const [customTranscriptionApiKey, setCustomTranscriptionApiKeyLocal] = useLocalStorage("customTranscriptionApiKey","",{@@ -160,7 +160,7 @@ export function useSettings() {});- const [customReasoningApiKey, setCustomReasoningApiKey] = useLocalStorage(+ const [customReasoningApiKey, setCustomReasoningApiKeyLocal] = useLocalStorage("customReasoningApiKey","",{@@ -195,6 +195,14 @@ export function useSettings() {const envKey = await window.electronAPI.getGroqKey?.();if (envKey) setGroqApiKeyLocal(envKey);}+ if (!customTranscriptionApiKey) {+ const envKey = await window.electronAPI.getCustomTranscriptionKey?.();+ if (envKey) setCustomTranscriptionApiKeyLocal(envKey);+ }+ if (!customReasoningApiKey) {+ const envKey = await window.electronAPI.getCustomReasoningKey?.();+ if (envKey) setCustomReasoningApiKeyLocal(envKey);+ }};syncKeys().catch(() => {@@ -252,6 +260,25 @@ export function useSettings() {[setGroqApiKeyLocal, debouncedPersistToEnv]);+ const setCustomTranscriptionApiKey = useCallback(+ (key: string) => {+ setCustomTranscriptionApiKeyLocal(key);+ window.electronAPI?.saveCustomTranscriptionKey?.(key);+ debouncedPersistToEnv();+ },+ [setCustomTranscriptionApiKeyLocal, debouncedPersistToEnv]+ );++ const setCustomReasoningApiKey = useCallback(+ (key: string) => {+ setCustomReasoningApiKeyLocal(key);+ window.electronAPI?.saveCustomReasoningKey?.(key);+ ReasoningService.clearApiKeyCache("custom");+ debouncedPersistToEnv();+ },+ [setCustomReasoningApiKeyLocal, debouncedPersistToEnv]+ );+// Hotkeyconst [dictationKey, setDictationKey] = useLocalStorage("dictationKey", "", {serialize: String,diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.tsindex 6b78a59b6..95c647fdd 100644--- a/src/services/ReasoningService.ts+++ b/src/services/ReasoningService.ts@@ -186,9 +186,16 @@ class ReasoningService extends BaseReasoningService {private async getApiKey(provider: "openai" | "anthropic" | "gemini" | "groq" | "custom"): Promise<string> {- // For custom provider, get API key from localStorage (not from .env)if (provider === "custom") {- const customKey = window.localStorage?.getItem("customReasoningApiKey") || "";+ let customKey = "";+ try {+ customKey = (await window.electronAPI?.getCustomReasoningKey?.()) || "";+ } catch (err) {+ logger.logReasoning("CUSTOM_KEY_IPC_FALLBACK", { error: (err as Error)?.message });+ }+ if (!customKey || !customKey.trim()) {+ customKey = window.localStorage?.getItem("customReasoningApiKey") || "";+ }const trimmedKey = customKey.trim();logger.logReasoning("CUSTOM_KEY_RETRIEVAL", {@@ -198,6 +205,7 @@ class ReasoningService extends BaseReasoningService {keyPreview: trimmedKey ? `${trimmedKey.substring(0, 8)}...` : "none",});+ // Custom endpoints may not require an API keyreturn trimmedKey;}@@ -1030,10 +1038,14 @@ class ReasoningService extends BaseReasoningService {/*** Clear cached API key for a specific provider or all providers.* Call this when API keys change to ensure fresh keys are used.+ * Note: "custom" keys are not cached (read fresh from localStorage each time).*/- clearApiKeyCache(provider?: "openai" | "anthropic" | "gemini" | "groq"): void {+ clearApiKeyCache(provider?: "openai" | "anthropic" | "gemini" | "groq" | "custom"): void {if (provider) {- this.apiKeyCache.delete(provider);+ // Custom keys aren't cached, but we accept the type for consistency+ if (provider !== "custom") {+ this.apiKeyCache.delete(provider);+ }logger.logReasoning("API_KEY_CACHE_CLEARED", { provider });} else {this.apiKeyCache.clear();