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: enforce single instance lock and add isLiveWindow helper for cleaner window state checks
Gabriel Stein54f61dcd63ec
diff --git a/main.js b/main.jsindex 84a7a6b6c..37e31fcf0 100644--- a/main.js+++ b/main.js@@ -1,5 +1,13 @@const { app, globalShortcut, BrowserWindow, dialog } = require("electron");+const gotSingleInstanceLock = app.requestSingleInstanceLock();++if (!gotSingleInstanceLock) {+ app.exit(0);+}++const isLiveWindow = (window) => window && !window.isDestroyed();+// Ensure macOS menus use the proper casing for the app nameif (process.platform === "darwin" && app.getName() !== "OpenWhispr") {app.setName("OpenWhispr");@@ -153,11 +161,11 @@ async function startApp() {}// Set up tray-trayManager.setWindows(- windowManager.mainWindow,- windowManager.controlPanelWindow-);-trayManager.setWindowManager(windowManager);+ trayManager.setWindows(+ windowManager.mainWindow,+ windowManager.controlPanelWindow+ );+ trayManager.setWindowManager(windowManager);trayManager.setCreateControlPanelCallback(() =>windowManager.createControlPanelWindow());@@ -177,19 +185,13 @@ trayManager.setWindowManager(windowManager);globeKeyManager.on("globe-down", async () => {// Forward to control panel for hotkey capture- if (- windowManager.controlPanelWindow &&- !windowManager.controlPanelWindow.isDestroyed()- ) {+ if (isLiveWindow(windowManager.controlPanelWindow)) {windowManager.controlPanelWindow.webContents.send("globe-key-pressed");}// Handle dictation if Globe is the current hotkeyif (hotkeyManager.getCurrentHotkey && hotkeyManager.getCurrentHotkey() === "GLOBE") {- if (- windowManager.mainWindow &&- !windowManager.mainWindow.isDestroyed()- ) {+ if (isLiveWindow(windowManager.mainWindow)) {const activationMode = await windowManager.getActivationMode();windowManager.showDictationPanel();if (activationMode === "push") {@@ -232,67 +234,88 @@ trayManager.setWindowManager(windowManager);}// App event handlers-app.whenReady().then(() => {- // Hide dock icon on macOS for a cleaner experience- // The app will still show in the menu bar and command bar- if (process.platform === 'darwin' && app.dock) {- // Keep dock visible for now to maintain command bar access- // We can hide it later if needed: app.dock.hide()- }-- startApp();-});+if (gotSingleInstanceLock) {+ app.on("second-instance", async () => {+ await app.whenReady();+ if (!windowManager) {+ return;+ }-app.on("window-all-closed", () => {- // Don't quit on macOS when all windows are closed- // The app should stay in the dock/menu bar- if (process.platform !== "darwin") {- app.quit();- }- // On macOS, keep the app running even without windows-});+ if (isLiveWindow(windowManager.controlPanelWindow)) {+ if (windowManager.controlPanelWindow.isMinimized()) {+ windowManager.controlPanelWindow.restore();+ }+ windowManager.controlPanelWindow.show();+ windowManager.controlPanelWindow.focus();+ } else {+ windowManager.createControlPanelWindow();+ }-app.on("browser-window-focus", (event, window) => {- // Only apply always-on-top to the dictation window, not the control panel- if (windowManager && windowManager.mainWindow && !windowManager.mainWindow.isDestroyed()) {- // Check if the focused window is the dictation window- if (window === windowManager.mainWindow) {+ if (isLiveWindow(windowManager.mainWindow)) {windowManager.enforceMainWindowOnTop();+ } else {+ windowManager.createMainWindow();}- }+ });- // Control panel doesn't need any special handling on focus- // It should behave like a normal window-});+ app.whenReady().then(() => {+ startApp();+ });-app.on("activate", () => {- // On macOS, re-create windows when dock icon is clicked- if (BrowserWindow.getAllWindows().length === 0) {- if (windowManager) {- windowManager.createMainWindow();- windowManager.createControlPanelWindow();+ app.on("window-all-closed", () => {+ // Don't quit on macOS when all windows are closed+ // The app should stay in the dock/menu bar+ if (process.platform !== "darwin") {+ app.quit();}- } else {- // Show control panel when dock icon is clicked (most common user action)- if (windowManager && windowManager.controlPanelWindow && !windowManager.controlPanelWindow.isDestroyed()) {- windowManager.controlPanelWindow.show();- windowManager.controlPanelWindow.focus();- } else if (windowManager) {- // If control panel doesn't exist, create it- windowManager.createControlPanelWindow();+ // On macOS, keep the app running even without windows+ });++ app.on("browser-window-focus", (event, window) => {+ // Only apply always-on-top to the dictation window, not the control panel+ if (windowManager && isLiveWindow(windowManager.mainWindow)) {+ // Check if the focused window is the dictation window+ if (window === windowManager.mainWindow) {+ windowManager.enforceMainWindowOnTop();+ }}-- // Ensure dictation panel maintains its always-on-top status- if (windowManager && windowManager.mainWindow && !windowManager.mainWindow.isDestroyed()) {- windowManager.enforceMainWindowOnTop();++ // Control panel doesn't need any special handling on focus+ // It should behave like a normal window+ });++ app.on("activate", () => {+ // On macOS, re-create windows when dock icon is clicked+ if (BrowserWindow.getAllWindows().length === 0) {+ if (windowManager) {+ windowManager.createMainWindow();+ windowManager.createControlPanelWindow();+ }+ } else {+ // Show control panel when dock icon is clicked (most common user action)+ if (windowManager && isLiveWindow(windowManager.controlPanelWindow)) {+ if (windowManager.controlPanelWindow.isMinimized()) {+ windowManager.controlPanelWindow.restore();+ }+ windowManager.controlPanelWindow.show();+ windowManager.controlPanelWindow.focus();+ } else if (windowManager) {+ // If control panel doesn't exist, create it+ windowManager.createControlPanelWindow();+ }++ // Ensure dictation panel maintains its always-on-top status+ if (windowManager && isLiveWindow(windowManager.mainWindow)) {+ windowManager.enforceMainWindowOnTop();+ }}- }-});+ });-app.on("will-quit", () => {- globalShortcut.unregisterAll();- globeKeyManager.stop();- updateManager.cleanup();- // Stop whisper server if running- whisperManager.stopServer().catch(() => {});-});+ app.on("will-quit", () => {+ globalShortcut.unregisterAll();+ globeKeyManager.stop();+ updateManager.cleanup();+ // Stop whisper server if running+ whisperManager.stopServer().catch(() => {});+ });+}