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: fixed python version detection in development
Gabriel Stein02ecc45e8232
diff --git a/main.js b/main.jsindex f7fcff2c0..86d3936d3 100644--- a/main.js+++ b/main.js@@ -26,6 +26,33 @@ const TrayManager = require("./src/helpers/tray");const IPCHandlers = require("./src/helpers/ipcHandlers");const UpdateManager = require("./src/updater");+// Set up PATH for production builds to find system Python+function setupProductionPath() {+ if (process.platform === 'darwin' && process.env.NODE_ENV !== 'development') {+ const commonPaths = [+ '/usr/local/bin',+ '/opt/homebrew/bin',+ '/usr/bin',+ '/bin',+ '/usr/sbin',+ '/sbin',+ '/Library/Frameworks/Python.framework/Versions/3.11/bin',+ '/Library/Frameworks/Python.framework/Versions/3.10/bin',+ '/Library/Frameworks/Python.framework/Versions/3.9/bin'+ ];++ const currentPath = process.env.PATH || '';+ const pathsToAdd = commonPaths.filter(p => !currentPath.includes(p));++ if (pathsToAdd.length > 0) {+ process.env.PATH = `${currentPath}:${pathsToAdd.join(':')}`;+ }+ }+}++// Set up PATH before initializing managers+setupProductionPath();+// Initialize managersconst environmentManager = new EnvironmentManager();const windowManager = new WindowManager();@@ -95,9 +122,9 @@ async function startApp() {// App event handlersapp.whenReady().then(() => {- // Log debug status- if (debugLogger.isEnabled()) {- console.log(`π Debug mode enabled - Logs saved to: ${debugLogger.getLogPath()}`);+ // Only log debug status in development+ if (debugLogger.isEnabled() && process.env.NODE_ENV === 'development') {+ console.log(`Debug logging enabled: ${debugLogger.getLogPath()}`);}startApp();diff --git a/src/helpers/database.js b/src/helpers/database.jsindex 5febfdaa6..f7b427b0d 100644--- a/src/helpers/database.js+++ b/src/helpers/database.js@@ -12,21 +12,15 @@ class DatabaseManager {initDatabase() {try {- console.log("π Starting database initialization...");-const dbFileName =process.env.NODE_ENV === "development"? "transcriptions-dev.db": "transcriptions.db";const dbPath = path.join(app.getPath("userData"), dbFileName);- console.log("π Database path:", dbPath);- console.log("π§ Creating database connection...");this.db = new Database(dbPath);- console.log("β Database connection created");- console.log("π Creating transcriptions table...");this.db.exec(`CREATE TABLE IF NOT EXISTS transcriptions (id INTEGER PRIMARY KEY AUTOINCREMENT,@@ -35,24 +29,10 @@ class DatabaseManager {created_at DATETIME DEFAULT CURRENT_TIMESTAMP)`);- console.log("β Transcriptions table created/verified");-- console.log("π Counting existing transcriptions...");- const countStmt = this.db.prepare(- "SELECT COUNT(*) as count FROM transcriptions"- );- const { count } = countStmt.get();- console.log(- `β Database initialized successfully (${count} existing transcriptions)`- );return true;} catch (error) {- console.error("β Database initialization failed:", error);- console.error("Error details:", {- message: error.message,- stack: error.stack,- });+ console.error("Database initialization failed:", error.message);throw error;}}@@ -67,20 +47,10 @@ class DatabaseManager {);const result = stmt.run(text);- const truncatedText =- text.length > 50 ? text.substring(0, 50) + "..." : text;- console.log(- `π Transcription saved to ${process.env.NODE_ENV || "production"} DB:`,- {- id: result.lastInsertRowid,- text: truncatedText,- length: text.length,- }- );return { id: result.lastInsertRowid, success: true };} catch (error) {- console.error("β Error saving transcription:", error);+ console.error("Error saving transcription:", error.message);throw error;}}@@ -94,14 +64,9 @@ class DatabaseManager {"SELECT * FROM transcriptions ORDER BY timestamp DESC LIMIT ?");const transcriptions = stmt.all(limit);- console.log(- `π Retrieved ${transcriptions.length} transcriptions from ${- process.env.NODE_ENV || "production"- } DB (limit: ${limit})`- );return transcriptions;} catch (error) {- console.error("β Error getting transcriptions:", error);+ console.error("Error getting transcriptions:", error.message);throw error;}}@@ -113,14 +78,9 @@ class DatabaseManager {}const stmt = this.db.prepare("DELETE FROM transcriptions");const result = stmt.run();- console.log(- `ποΈ Cleared ${result.changes} transcriptions from ${- process.env.NODE_ENV || "production"- } DB`- );return { cleared: result.changes, success: true };} catch (error) {- console.error("β Error clearing transcriptions:", error);+ console.error("Error clearing transcriptions:", error.message);throw error;}}diff --git a/src/helpers/pythonInstaller.js b/src/helpers/pythonInstaller.jsindex ffd9983b7..c449adc3a 100644--- a/src/helpers/pythonInstaller.js+++ b/src/helpers/pythonInstaller.js@@ -295,7 +295,6 @@ class PythonInstaller {}} catch (error) {- console.error("Python installation failed:", error);throw error;}}@@ -303,6 +302,19 @@ class PythonInstaller {async isPythonInstalled() {const possibleCommands = ['python3.11', 'python3', 'python'];+ // On macOS, also check common Python installation paths+ const additionalPaths = process.platform === 'darwin' ? [+ '/usr/local/bin/python3',+ '/usr/local/bin/python3.11',+ '/opt/homebrew/bin/python3',+ '/opt/homebrew/bin/python3.11',+ '/usr/bin/python3',+ '/Library/Frameworks/Python.framework/Versions/3.11/bin/python3',+ '/Library/Frameworks/Python.framework/Versions/3.10/bin/python3',+ '/Library/Frameworks/Python.framework/Versions/3.9/bin/python3',+ ] : [];++ // First check commands in PATHfor (const cmd of possibleCommands) {try {const result = await runCommand(cmd, ['--version'], { timeout: TIMEOUTS.QUICK_CHECK });@@ -319,6 +331,25 @@ class PythonInstaller {}}+ // Then check absolute paths on macOS+ for (const fullPath of additionalPaths) {+ try {+ const fs = require('fs');+ if (fs.existsSync(fullPath)) {+ const result = await runCommand(fullPath, ['--version'], { timeout: TIMEOUTS.QUICK_CHECK });+ const versionMatch = result.output.match(/Python (\d+\.\d+)/);+ if (versionMatch) {+ const version = parseFloat(versionMatch[1]);+ if (version >= 3.0) {+ return { installed: true, command: fullPath, version: version };+ }+ }+ }+ } catch (error) {+ continue;+ }+ }+return { installed: false };}}diff --git a/src/hooks/usePython.ts b/src/hooks/usePython.tsindex 457c3e05d..be8380b77 100644--- a/src/hooks/usePython.ts+++ b/src/hooks/usePython.ts@@ -40,36 +40,45 @@ export function usePython(showAlertDialog: ShowAlertDialog) {const [installingPython, setInstallingPython] = useState<boolean>(false);const [installProgress, setInstallProgress] = useState<string>("");const [pythonInfo, setPythonInfo] = useState<PythonInstallation | null>(null);- const mountedRef = useRef(true);-- // Cleanup on unmount- useEffect(() => {- return () => {- mountedRef.current = false;- };- }, []);+ const [isChecking, setIsChecking] = useState<boolean>(false);const checkPythonInstallation = useCallback(async () => {+ if (isChecking) {+ return pythonInfo || { installed: false };+ }+try {- const result = await window.electronAPI?.checkPythonInstallation();- if (result && mountedRef.current) {+ setIsChecking(true);++ if (!window.electronAPI) {+ return { installed: false };+ }++ const result = await window.electronAPI.checkPythonInstallation();++ if (result) {setPythonInstalled(result.installed);setPythonInfo(result);return result;}return { installed: false };} catch (error) {- console.error("Error checking Python installation:", error);- if (mountedRef.current) {- setPythonInstalled(false);- }+ setPythonInstalled(false);return { installed: false };+ } finally {+ setIsChecking(false);}- }, []);+ }, [isChecking, pythonInfo]);const installPython = useCallback(async () => {- console.log("installPython called");- if (!mountedRef.current) return;++ if (!window.electronAPI) {+ showAlertDialog({+ title: "Installation Error",+ description: "Unable to communicate with the main process. Please restart the application.",+ });+ return;+ }let progressListener: ((event: any, data: PythonInstallProgress) => void) | null = null;@@ -77,24 +86,20 @@ export function usePython(showAlertDialog: ShowAlertDialog) {setInstallingPython(true);setInstallProgress("Starting Python installation...");- progressListener = (_event: any, data: PythonInstallProgress) => {- if (!mountedRef.current) return;-- if (data.type === "progress") {+ progressListener = (_event: any, data: any) => {+ if (data?.type === "progress" && data?.stage && data?.percentage !== undefined) {setInstallProgress(`${data.stage} (${data.percentage}%)`);}};// Listen for progress updates- if (window.electronAPI?.onPythonInstallProgress) {+ if (window.electronAPI.onPythonInstallProgress) {window.electronAPI.onPythonInstallProgress(progressListener);}- console.log("Calling window.electronAPI.installPython");- const result = await window.electronAPI?.installPython();- console.log("Install result:", result);+ const result = await window.electronAPI.installPython();- if (mountedRef.current && result?.success) {+ if (result?.success) {setPythonInstalled(true);setInstallProgress("Python installed successfully!");@@ -109,10 +114,6 @@ export function usePython(showAlertDialog: ShowAlertDialog) {return result;} catch (error: any) {- if (!mountedRef.current) return;-- console.error("Python installation failed:", error);-const errorMessage = getPythonInstallErrorMessage(error);showAlertDialog({@@ -122,9 +123,7 @@ export function usePython(showAlertDialog: ShowAlertDialog) {throw error;} finally {- if (mountedRef.current) {- setInstallingPython(false);- }+ setInstallingPython(false);// Clean up the listenerif (progressListener) {window.electronAPI?.removeAllListeners?.("python-install-progress");@@ -132,9 +131,14 @@ export function usePython(showAlertDialog: ShowAlertDialog) {}}, [showAlertDialog, checkPythonInstallation]);- // Check Python installation on mount+ // Check Python installation on mount with a small delay to ensure preload is readyuseEffect(() => {- checkPythonInstallation();+ // In development, there might be a race condition where React loads before preload+ const timer = setTimeout(() => {+ checkPythonInstallation();+ }, 100); // Small delay to ensure preload script is ready++ return () => clearTimeout(timer);}, [checkPythonInstallation]);return {@@ -144,5 +148,6 @@ export function usePython(showAlertDialog: ShowAlertDialog) {pythonInfo,installPython,checkPythonInstallation,+ isChecking,};}\ No newline at end of file