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: cache accessibility, paste tool, and FFmpeg availability checks to reduce repeated process spawns
Gabriel Stein416c6c5e0b9d
diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.jsindex fb3fdd39d..26b6d74f0 100644--- a/src/helpers/clipboard.js+++ b/src/helpers/clipboard.js@@ -1,9 +1,14 @@const { clipboard } = require("electron");const { spawn, spawnSync } = require("child_process");+const ACCESSIBILITY_CACHE_TTL_MS = 30000;+const TOOL_CACHE_TTL_MS = 30000;+class ClipboardManager {constructor() {- // Initialize clipboard manager+ this.accessibilityCache = { value: null, expiresAt: 0 };+ this.commandAvailabilityCache = new Map();+ this.availablePasteToolsCache = new Map();}// Safe logging method - only log in development@@ -157,12 +162,26 @@ class ClipboardManager {async pasteLinux(originalClipboard) {// Helper to check if a command existsconst commandExists = (cmd) => {+ const now = Date.now();+ const cached = this.commandAvailabilityCache.get(cmd);+ if (cached && now < cached.expiresAt) {+ return cached.exists;+ }try {const res = spawnSync("sh", ["-c", `command -v ${cmd}`], {stdio: "ignore",});- return res.status === 0;+ const exists = res.status === 0;+ this.commandAvailabilityCache.set(cmd, {+ exists,+ expiresAt: now + TOOL_CACHE_TTL_MS,+ });+ return exists;} catch {+ this.commandAvailabilityCache.set(cmd, {+ exists: false,+ expiresAt: now + TOOL_CACHE_TTL_MS,+ });return false;}};@@ -264,8 +283,19 @@ class ClipboardManager {{ cmd: "xdotool", args: ["key", pasteKeys] },];- // Filter to only available tools- const available = candidates.filter((c) => commandExists(c.cmd));+ // Filter to only available tools (cached by session type)+ const cacheKey = `${isWayland ? "wayland" : "x11"}:${inTerminal ? "term" : "gui"}`;+ const cacheEntry = this.availablePasteToolsCache.get(cacheKey);+ let available;+ if (cacheEntry && Date.now() < cacheEntry.expiresAt) {+ available = cacheEntry.tools;+ } else {+ available = candidates.filter((c) => commandExists(c.cmd));+ this.availablePasteToolsCache.set(cacheKey, {+ tools: available,+ expiresAt: Date.now() + TOOL_CACHE_TTL_MS,+ });+ }// Attempt paste with a specific toolconst pasteWith = (tool) =>@@ -332,6 +362,14 @@ class ClipboardManager {async checkAccessibilityPermissions() {if (process.platform !== "darwin") return true;+ const now = Date.now();+ if (+ now < this.accessibilityCache.expiresAt &&+ this.accessibilityCache.value !== null+ ) {+ return this.accessibilityCache.value;+ }+return new Promise((resolve) => {// Check accessibility permissions@@ -352,15 +390,22 @@ class ClipboardManager {});testProcess.on("close", (code) => {- if (code === 0) {- resolve(true);- } else {+ const allowed = code === 0;+ this.accessibilityCache = {+ value: allowed,+ expiresAt: Date.now() + ACCESSIBILITY_CACHE_TTL_MS,+ };+ if (!allowed) {this.showAccessibilityDialog(testError);- resolve(false);}+ resolve(allowed);});testProcess.on("error", (error) => {+ this.accessibilityCache = {+ value: false,+ expiresAt: Date.now() + ACCESSIBILITY_CACHE_TTL_MS,+ };resolve(false);});});diff --git a/src/helpers/whisper.js b/src/helpers/whisper.jsindex 4da42fcca..74b0c9442 100644--- a/src/helpers/whisper.js+++ b/src/helpers/whisper.js@@ -8,6 +8,8 @@ const PythonInstaller = require("./pythonInstaller");const { runCommand, TIMEOUTS } = require("../utils/process");const debugLogger = require("./debugLogger");+const FFMPEG_AVAILABILITY_CACHE_TTL = 30000;+class WhisperManager {constructor() {this.pythonCmd = null;@@ -16,6 +18,7 @@ class WhisperManager {this.currentDownloadProcess = null;this.pythonInstaller = new PythonInstaller();this.cachedFFmpegPath = null;+ this.ffmpegAvailabilityCache = { result: null, expiresAt: 0 };}sanitizeErrorMessage(message = "") {@@ -914,15 +917,29 @@ class WhisperManager {debugLogger.logWhisperPipeline('checkFFmpegAvailability - start', {});try {+ const now = Date.now();+ if (+ this.ffmpegAvailabilityCache &&+ now < this.ffmpegAvailabilityCache.expiresAt &&+ this.ffmpegAvailabilityCache.result !== null+ ) {+ return this.ffmpegAvailabilityCache.result;+ }+const pythonCmd = await this.findPythonExecutable();const whisperScriptPath = this.getWhisperScriptPath();const ffmpegPath = await this.getFFmpegPath();if (!ffmpegPath) {debugLogger.log('FFmpeg not found by resolver');- return {+ const result = {available: false,error: "FFmpeg not found"};+ this.ffmpegAvailabilityCache = {+ result,+ expiresAt: Date.now() + FFMPEG_AVAILABILITY_CACHE_TTL,+ };+ return result;}debugLogger.log('FFmpeg resolved for availability check:', ffmpegPath);@@ -987,9 +1004,18 @@ class WhisperManager {});});+ this.ffmpegAvailabilityCache = {+ result,+ expiresAt: Date.now() + FFMPEG_AVAILABILITY_CACHE_TTL,+ };return result;} catch (error) {- return { available: false, error: error.message };+ const result = { available: false, error: error.message };+ this.ffmpegAvailabilityCache = {+ result,+ expiresAt: Date.now() + FFMPEG_AVAILABILITY_CACHE_TTL,+ };+ return result;}}