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
Refactor Windows PTT into windowManager, add reentrancy guards to audio recording, sync getActivationMode callers, and add missing terminal classes to Windows paste binary
Gabriel Stein6a401e60d14b
diff --git a/main.js b/main.jsindex 17d03c120..5c85366ee 100644--- a/main.js+++ b/main.js@@ -531,7 +531,7 @@ async function startApp() {// Handle dictation if Globe is the current hotkeyif (hotkeyManager.getCurrentHotkey && hotkeyManager.getCurrentHotkey() === "GLOBE") {if (isLiveWindow(windowManager.mainWindow)) {- const activationMode = await windowManager.getActivationMode();+ const activationMode = windowManager.getActivationMode();if (activationMode === "push") {const now = Date.now();if (now - globeLastStopTime < POST_STOP_COOLDOWN_MS) return;@@ -561,7 +561,7 @@ async function startApp() {// Handle push-to-talk release if Globe is the current hotkeyif (hotkeyManager.getCurrentHotkey && hotkeyManager.getCurrentHotkey() === "GLOBE") {- const activationMode = await windowManager.getActivationMode();+ const activationMode = windowManager.getActivationMode();if (activationMode === "push") {globeKeyDownTime = 0;globeLastStopTime = Date.now();@@ -592,7 +592,7 @@ async function startApp() {if (currentHotkey !== modifier) return;if (!isLiveWindow(windowManager.mainWindow)) return;- const activationMode = await windowManager.getActivationMode();+ const activationMode = windowManager.getActivationMode();if (activationMode === "push") {const now = Date.now();if (now - rightModLastStopTime < POST_STOP_COOLDOWN_MS) return;@@ -617,7 +617,7 @@ async function startApp() {if (currentHotkey !== modifier) return;if (!isLiveWindow(windowManager.mainWindow)) return;- const activationMode = await windowManager.getActivationMode();+ const activationMode = windowManager.getActivationMode();if (activationMode === "push") {rightModDownTime = 0;rightModLastStopTime = Date.now();@@ -646,21 +646,9 @@ async function startApp() {// Set up Windows Push-to-Talk handlingif (process.platform === "win32") {debugLogger.debug("[Push-to-Talk] Windows Push-to-Talk setup starting");- let winKeyDownTime = 0;- let winKeyIsRecording = false;- let winLastStopTime = 0;-- const WIN_MIN_HOLD_DURATION_MS = 150;- const WIN_POST_STOP_COOLDOWN_MS = 300;-- // Helper to check if hotkey is valid for Windows key listener- const isValidHotkey = (hotkey) => {- if (!hotkey) return false;- if (hotkey === "GLOBE") return false;- return true;- };- // Right-side single modifiers need the native listener even in tap mode+ const isValidHotkey = (hotkey) => hotkey && hotkey !== "GLOBE";+const isRightSideMod = (hotkey) =>/^Right(Control|Ctrl|Alt|Option|Shift|Super|Win|Meta|Command|Cmd)$/i.test(hotkey);@@ -672,60 +660,29 @@ async function startApp() {return isRightSideMod(hotkey) || isModifierOnlyHotkey(hotkey);};- windowsKeyManager.on("key-down", async (key) => {- debugLogger.debug("[Push-to-Talk] Key DOWN received", { key });+ windowsKeyManager.on("key-down", (_key) => {if (!isLiveWindow(windowManager.mainWindow)) return;- const activationMode = await windowManager.getActivationMode();- debugLogger.debug("[Push-to-Talk] Activation mode check", { activationMode });+ const activationMode = windowManager.getActivationMode();if (activationMode === "push") {- const now = Date.now();- if (now - winLastStopTime < WIN_POST_STOP_COOLDOWN_MS) {- debugLogger.debug("[Push-to-Talk] Ignoring KEY_DOWN during post-stop cooldown");- return;- }-- debugLogger.debug("[Push-to-Talk] Starting recording sequence");- windowManager.showDictationPanel();- const pressTime = now;- winKeyDownTime = pressTime;- winKeyIsRecording = false;- setTimeout(async () => {- if (winKeyDownTime === pressTime && !winKeyIsRecording) {- winKeyIsRecording = true;- debugLogger.debug("[Push-to-Talk] Sending start dictation command");- windowManager.sendStartDictation();- }- }, WIN_MIN_HOLD_DURATION_MS);+ windowManager.startWindowsPushToTalk();} else if (activationMode === "tap") {windowManager.showDictationPanel();windowManager.mainWindow.webContents.send("toggle-dictation");}});- windowsKeyManager.on("key-up", async () => {- debugLogger.debug("[Push-to-Talk] Key UP received");+ windowsKeyManager.on("key-up", () => {if (!isLiveWindow(windowManager.mainWindow)) return;- const activationMode = await windowManager.getActivationMode();+ const activationMode = windowManager.getActivationMode();if (activationMode === "push") {- const wasRecording = winKeyIsRecording;- winKeyDownTime = 0;- winKeyIsRecording = false;- winLastStopTime = Date.now();- if (wasRecording) {- debugLogger.debug("[Push-to-Talk] Sending stop dictation command");- windowManager.sendStopDictation();- } else {- debugLogger.debug("[Push-to-Talk] Short tap detected, hiding panel");- windowManager.hideDictationPanel();- }+ windowManager.handleWindowsPushKeyUp();}});windowsKeyManager.on("error", (error) => {debugLogger.warn("[Push-to-Talk] Windows key listener error", { error: error.message });- windowManager.setWindowsPushToTalkAvailable(false);if (isLiveWindow(windowManager.mainWindow)) {windowManager.mainWindow.webContents.send("windows-ptt-unavailable", {reason: "error",@@ -738,7 +695,6 @@ async function startApp() {debugLogger.debug("[Push-to-Talk] Windows key listener not available - falling back to toggle mode");- windowManager.setWindowsPushToTalkAvailable(false);if (isLiveWindow(windowManager.mainWindow)) {windowManager.mainWindow.webContents.send("windows-ptt-unavailable", {reason: "binary_not_found",@@ -749,55 +705,37 @@ async function startApp() {windowsKeyManager.on("ready", () => {debugLogger.debug("[Push-to-Talk] WindowsKeyManager is ready and listening");- windowManager.setWindowsPushToTalkAvailable(true);});- // Start the Windows key listener with the current hotkey- const startWindowsKeyListener = async () => {- debugLogger.debug("[Push-to-Talk] Checking if should start Windows key listener");- if (!isLiveWindow(windowManager.mainWindow)) {- debugLogger.debug("[Push-to-Talk] Main window not live, skipping");- return;- }- const activationMode = await windowManager.getActivationMode();+ const startWindowsKeyListener = () => {+ if (!isLiveWindow(windowManager.mainWindow)) return;+ const activationMode = windowManager.getActivationMode();const currentHotkey = hotkeyManager.getCurrentHotkey();- debugLogger.debug("[Push-to-Talk] Current state", { activationMode, currentHotkey });if (needsNativeListener(currentHotkey, activationMode)) {- debugLogger.debug("[Push-to-Talk] Starting Windows key listener", {- hotkey: currentHotkey,- });windowsKeyManager.start(currentHotkey);- } else {- debugLogger.debug("[Push-to-Talk] Native listener not needed for current configuration");}};const STARTUP_DELAY_MS = 3000;- debugLogger.debug("[Push-to-Talk] Scheduling listener start", { delayMs: STARTUP_DELAY_MS });setTimeout(startWindowsKeyListener, STARTUP_DELAY_MS);- // Listen for activation mode changes from renderer- ipcMain.on("activation-mode-changed", async (_event, mode) => {- debugLogger.debug("[Push-to-Talk] IPC: Activation mode changed", { mode });+ ipcMain.on("activation-mode-changed", (_event, mode) => {+ windowManager.resetWindowsPushState();const currentHotkey = hotkeyManager.getCurrentHotkey();if (needsNativeListener(currentHotkey, mode)) {- debugLogger.debug("[Push-to-Talk] Starting listener", { hotkey: currentHotkey });windowsKeyManager.start(currentHotkey);} else {- debugLogger.debug("[Push-to-Talk] Stopping listener");windowsKeyManager.stop();}});- // Listen for hotkey changes from renderer- ipcMain.on("hotkey-changed", async (_event, hotkey) => {- debugLogger.debug("[Push-to-Talk] IPC: Hotkey changed", { hotkey });+ ipcMain.on("hotkey-changed", (_event, hotkey) => {if (!isLiveWindow(windowManager.mainWindow)) return;- const activationMode = await windowManager.getActivationMode();+ windowManager.resetWindowsPushState();+ const activationMode = windowManager.getActivationMode();windowsKeyManager.stop();if (needsNativeListener(hotkey, activationMode)) {- debugLogger.debug("[Push-to-Talk] Starting listener for new hotkey", { hotkey });windowsKeyManager.start(hotkey);}});diff --git a/resources/windows-fast-paste.c b/resources/windows-fast-paste.cindex 7e72118b2..2272800dc 100644--- a/resources/windows-fast-paste.c+++ b/resources/windows-fast-paste.c@@ -25,6 +25,7 @@ static const char* TERMINAL_CLASSES[] = {"org.wezfurlong.wezterm","Hyper","TMobaXterm",+ "kitty",NULL};diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex 6f48eaabc..37a27c55b 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -548,7 +548,7 @@ class IPCHandlers {}if (process.platform === "win32" && this.windowsKeyManager) {- const activationMode = await this.windowManager.getActivationMode();+ const activationMode = this.windowManager.getActivationMode();debugLogger.log(`[IPC] Exiting hotkey capture mode, activationMode="${activationMode}", hotkey="${effectiveHotkey}"`);diff --git a/src/helpers/windowManager.js b/src/helpers/windowManager.jsindex 9616bfc9d..865193f69 100644--- a/src/helpers/windowManager.js+++ b/src/helpers/windowManager.js@@ -22,8 +22,8 @@ class WindowManager {this.isQuitting = false;this.isMainWindowInteractive = false;this.loadErrorShown = false;- this.windowsPushToTalkAvailable = false;this.macCompoundPushState = null;+ this.winPushState = null;this._cachedActivationMode = "tap";this._floatingIconAutoHide = false;@@ -32,10 +32,6 @@ class WindowManager {});}- setWindowsPushToTalkAvailable(available) {- this.windowsPushToTalkAvailable = available;- }-async createMainWindow() {const display = screen.getPrimaryDisplay();const position = WindowPositionUtil.getMainWindowPosition(display);@@ -165,7 +161,7 @@ class WindowManager {return;}- const activationMode = await this.getActivationMode();+ const activationMode = this.getActivationMode();const currentHotkey = this.hotkeyManager.getCurrentHotkey?.();if (@@ -179,11 +175,9 @@ class WindowManager {return;}- // Windows push mode: defer to windowsKeyManager if available, else fall through to toggle- if (process.platform === "win32" && this.windowsPushToTalkAvailable) {- if (activationMode === "push") {- return;- }+ // Windows push mode: always defer to native listener (globalShortcut can't detect key-up)+ if (process.platform === "win32" && activationMode === "push") {+ return;}const now = Date.now();@@ -320,6 +314,53 @@ class WindowManager {return required;}+ startWindowsPushToTalk() {+ if (this.winPushState?.active) {+ return;+ }++ const MIN_HOLD_DURATION_MS = 150;+ const downTime = Date.now();++ this.showDictationPanel();++ this.winPushState = {+ active: true,+ downTime,+ isRecording: false,+ };++ setTimeout(() => {+ if (!this.winPushState || this.winPushState.downTime !== downTime) {+ return;+ }++ if (!this.winPushState.isRecording) {+ this.winPushState.isRecording = true;+ this.sendStartDictation();+ }+ }, MIN_HOLD_DURATION_MS);+ }++ handleWindowsPushKeyUp() {+ if (!this.winPushState?.active) {+ return;+ }++ const wasRecording = this.winPushState.isRecording;+ this.winPushState = null;++ if (wasRecording) {+ this.sendStopDictation();+ } else {+ this.hideDictationPanel();+ }+ }++ resetWindowsPushState() {+ this.winPushState = null;+ }+sendStartDictation() {if (this.hotkeyManager.isInListeningMode()) {return;@@ -501,6 +542,9 @@ class WindowManager {showDictationPanel(options = {}) {const { focus = false } = options;if (this.mainWindow && !this.mainWindow.isDestroyed()) {+ if (this.mainWindow.isMinimized()) {+ this.mainWindow.restore();+ }if (!this.mainWindow.isVisible()) {if (typeof this.mainWindow.showInactive === "function") {this.mainWindow.showInactive();@@ -528,11 +572,7 @@ class WindowManager {hideDictationPanel() {if (this.mainWindow && !this.mainWindow.isDestroyed()) {- if (process.platform === "darwin") {- this.mainWindow.hide();- } else {- this.mainWindow.minimize();- }+ this.mainWindow.hide();}}diff --git a/src/hooks/useAudioRecording.js b/src/hooks/useAudioRecording.jsindex ba9fd34a1..dcaae77f9 100644--- a/src/hooks/useAudioRecording.js+++ b/src/hooks/useAudioRecording.js@@ -12,51 +12,57 @@ export const useAudioRecording = (toast, options = {}) => {const [transcript, setTranscript] = useState("");const [partialTranscript, setPartialTranscript] = useState("");const audioManagerRef = useRef(null);+ const startLockRef = useRef(false);+ const stopLockRef = useRef(false);const { onToggle } = options;const performStartRecording = useCallback(async () => {- if (!audioManagerRef.current) {- return false;- }+ if (startLockRef.current) return false;+ startLockRef.current = true;+ try {+ if (!audioManagerRef.current) return false;- const currentState = audioManagerRef.current.getState();- if (currentState.isRecording || currentState.isProcessing) {- return false;- }+ const currentState = audioManagerRef.current.getState();+ if (currentState.isRecording || currentState.isProcessing) return false;- const didStart = audioManagerRef.current.shouldUseStreaming()- ? await audioManagerRef.current.startStreamingRecording()- : await audioManagerRef.current.startRecording();+ const didStart = audioManagerRef.current.shouldUseStreaming()+ ? await audioManagerRef.current.startStreamingRecording()+ : await audioManagerRef.current.startRecording();- if (didStart) {- void playStartCue();- }+ if (didStart) {+ void playStartCue();+ }- return didStart;+ return didStart;+ } finally {+ startLockRef.current = false;+ }}, []);const performStopRecording = useCallback(async () => {- if (!audioManagerRef.current) {- return false;- }+ if (stopLockRef.current) return false;+ stopLockRef.current = true;+ try {+ if (!audioManagerRef.current) return false;- const currentState = audioManagerRef.current.getState();- if (!currentState.isRecording && !currentState.isStreamingStartInProgress) {- return false;- }+ const currentState = audioManagerRef.current.getState();+ if (!currentState.isRecording && !currentState.isStreamingStartInProgress) return false;- if (currentState.isStreaming || currentState.isStreamingStartInProgress) {- void playStopCue(); // streaming stop finalization is async, play cue immediately on stop action- return await audioManagerRef.current.stopStreamingRecording();- }+ if (currentState.isStreaming || currentState.isStreamingStartInProgress) {+ void playStopCue();+ return await audioManagerRef.current.stopStreamingRecording();+ }- const didStop = audioManagerRef.current.stopRecording();+ const didStop = audioManagerRef.current.stopRecording();- if (didStop) {- void playStopCue();- }+ if (didStop) {+ void playStopCue();+ }- return didStop;+ return didStop;+ } finally {+ stopLockRef.current = false;+ }}, []);useEffect(() => {