Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

refactor: clean up window management and remove excess comments

Gabriel Steind4ef33462d24
diff --git a/src/helpers/ffmpegUtils.js b/src/helpers/ffmpegUtils.js
index 800bfaf91..3b60d5ee8 100644
--- a/src/helpers/ffmpegUtils.js
+++ b/src/helpers/ffmpegUtils.js
@@ -5,10 +5,6 @@ const debugLogger = require("./debugLogger");
let cachedFFmpegPath = null;
-/**
- * Get the path to FFmpeg binary, checking bundled and system locations
- * @returns {string|null} Path to FFmpeg binary or null if not found
- */
function getFFmpegPath() {
if (cachedFFmpegPath) return cachedFFmpegPath;
@@ -58,7 +54,6 @@ function getFFmpegPath() {
debugLogger.debug("Bundled FFmpeg not available", { error: err.message });
}
- // Try system FFmpeg locations
const systemCandidates =
process.platform === "darwin"
? ["/opt/homebrew/bin/ffmpeg", "/usr/local/bin/ffmpeg"]
@@ -73,7 +68,6 @@ function getFFmpegPath() {
}
}
- // Search PATH environment
const pathEnv = process.env.PATH || "";
const pathSep = process.platform === "win32" ? ";" : ":";
const pathDirs = pathEnv.split(pathSep).map((entry) => entry.replace(/^"|"$/g, ""));
@@ -98,15 +92,9 @@ function getFFmpegPath() {
return null;
}
-/**
- * Check if a buffer contains WAV audio format by examining the RIFF header
- * @param {Buffer} buffer - Audio buffer to check
- * @returns {boolean} True if buffer is WAV format
- */
function isWavFormat(buffer) {
if (!buffer || buffer.length < 12) return false;
- // Check for RIFF header and WAVE format
return (
buffer[0] === 0x52 && // R
buffer[1] === 0x49 && // I
@@ -119,15 +107,6 @@ function isWavFormat(buffer) {
);
}
-/**
- * Convert audio file to 16kHz mono WAV format using FFmpeg
- * @param {string} inputPath - Path to input audio file
- * @param {string} outputPath - Path to output WAV file
- * @param {Object} options - Conversion options
- * @param {number} options.sampleRate - Output sample rate (default: 16000)
- * @param {number} options.channels - Output channels (default: 1 for mono)
- * @returns {Promise<void>}
- */
function convertToWav(inputPath, outputPath, options = {}) {
const { sampleRate = 16000, channels = 1 } = options;
@@ -183,7 +162,6 @@ function convertToWav(inputPath, outputPath, options = {}) {
return;
}
- // Verify output file exists and has content
if (!fs.existsSync(outputPath)) {
reject(new Error("FFmpeg conversion produced no output file"));
return;
diff --git a/src/helpers/parakeetServer.js b/src/helpers/parakeetServer.js
index a56545b88..318077169 100644
--- a/src/helpers/parakeetServer.js
+++ b/src/helpers/parakeetServer.js
@@ -2,7 +2,13 @@ const fs = require("fs");
const path = require("path");
const debugLogger = require("./debugLogger");
const { getModelsDirForService } = require("./modelDirUtils");
-const { getFFmpegPath, isWavFormat, convertToWav, wavToFloat32Samples, computeFloat32RMS } = require("./ffmpegUtils");
+const {
+ getFFmpegPath,
+ isWavFormat,
+ convertToWav,
+ wavToFloat32Samples,
+ computeFloat32RMS,
+} = require("./ffmpegUtils");
const { getSafeTempDir } = require("./safeTempDir");
const ParakeetWsServer = require("./parakeetWsServer");
diff --git a/src/helpers/windowConfig.js b/src/helpers/windowConfig.js
index 51a459030..bd8a3cea5 100644
--- a/src/helpers/windowConfig.js
+++ b/src/helpers/windowConfig.js
@@ -63,13 +63,12 @@ const CONTROL_PANEL_CONFIG = {
maximizable: true,
closable: true,
fullscreenable: true,
- skipTaskbar: false, // Ensure control panel stays in taskbar
- alwaysOnTop: false, // Control panel should not be always on top
- visibleOnAllWorkspaces: false, // Control panel should stay in its workspace
- type: "normal", // Ensure it's a normal window, not a panel
+ skipTaskbar: false,
+ alwaysOnTop: false,
+ visibleOnAllWorkspaces: false,
+ type: "normal",
};
-// Window positioning utilities
class WindowPositionUtil {
static getMainWindowPosition(display, customSize = null) {
const { width, height } = customSize || WINDOW_SIZES.BASE;
@@ -91,27 +90,14 @@ class WindowPositionUtil {
});
window.setFullScreenable(false);
- // Ensure window level is maintained
if (window.isVisible()) {
window.setAlwaysOnTop(true, "floating", 1);
}
} else if (process.platform === "win32") {
window.setAlwaysOnTop(true, "pop-up-menu");
} else {
- // Linux and other platforms
window.setAlwaysOnTop(true, "screen-saver");
}
-
- // Bring window to front if visible
- if (window.isVisible()) {
- window.moveTop();
- }
- }
-
- static setupControlPanel(window) {
- // Control panel should behave like a normal application window
- // This is only called once during window creation
- // No need to repeatedly set these values
}
}
diff --git a/src/helpers/windowManager.js b/src/helpers/windowManager.js
index 54b70ed79..41eaab359 100644
--- a/src/helpers/windowManager.js
+++ b/src/helpers/windowManager.js
@@ -64,7 +64,6 @@ class WindowManager {
validatedURL &&
validatedURL.includes(`localhost:${DEV_SERVER_PORT}`)
) {
- // Retry connection to dev server
setTimeout(async () => {
const isReady = await DevServerManager.waitForDevServer();
if (isReady) {
@@ -82,7 +81,6 @@ class WindowManager {
this.enforceMainWindowOnTop();
});
- // Now load the window content
await this.loadMainWindow();
await this.initializeHotkey();
this.dragManager.setTargetWindow(this.mainWindow);
@@ -132,11 +130,6 @@ class WindowManager {
return { success: true, bounds: { x: newX, y: newY, ...newSize } };
}
- /**
- * Load content into a BrowserWindow, handling both dev server and production file loading.
- * @param {BrowserWindow} window - The window to load content into
- * @param {boolean} isControlPanel - Whether this is the control panel
- */
async loadWindowContent(window, isControlPanel = false) {
if (process.env.NODE_ENV === "development") {
const appUrl = DevServerManager.getAppUrl(isControlPanel);
@@ -198,9 +191,7 @@ class WindowManager {
}
lastToggleTime = now;
- if (!this.mainWindow.isVisible()) {
- this.mainWindow.show();
- }
+ this.showDictationPanel();
this.mainWindow.webContents.send("toggle-dictation");
};
}
@@ -221,7 +212,6 @@ class WindowManager {
this.showDictationPanel();
- // Set up safety timeout
const safetyTimeoutId = setTimeout(() => {
if (this.macCompoundPushState?.active) {
console.warn("[WindowManager] Compound PTT safety timeout triggered - stopping recording");
@@ -258,7 +248,6 @@ class WindowManager {
return;
}
- // Clear safety timeout
if (this.macCompoundPushState.safetyTimeoutId) {
clearTimeout(this.macCompoundPushState.safetyTimeoutId);
}
@@ -278,7 +267,6 @@ class WindowManager {
return;
}
- // Clear safety timeout
if (this.macCompoundPushState.safetyTimeoutId) {
clearTimeout(this.macCompoundPushState.safetyTimeoutId);
}
@@ -291,7 +279,6 @@ class WindowManager {
}
this.hideDictationPanel();
- // Notify renderer about forced stop
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
this.mainWindow.webContents.send("compound-ptt-force-stopped", { reason });
}
@@ -337,9 +324,7 @@ class WindowManager {
return;
}
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
- if (!this.mainWindow.isVisible()) {
- this.mainWindow.show();
- }
+ this.showDictationPanel();
this.mainWindow.webContents.send("start-dictation");
}
}
@@ -458,7 +443,6 @@ class WindowManager {
this.controlPanelWindow.once("ready-to-show", () => {
clearVisibilityTimer();
- // Show dock icon on macOS when control panel opens
if (process.platform === "darwin" && app.dock) {
app.dock.show();
}
@@ -482,7 +466,6 @@ class WindowManager {
this.controlPanelWindow = null;
});
- // Set up menu for control panel to ensure text input works
MenuManager.setupControlPanelMenu(this.controlPanelWindow);
this.controlPanelWindow.webContents.on("did-finish-load", () => {
@@ -537,7 +520,6 @@ class WindowManager {
this.controlPanelWindow.hide();
- // Hide dock icon on macOS when control panel is hidden
if (process.platform === "darwin" && app.dock) {
app.dock.hide();
}
@@ -578,7 +560,7 @@ class WindowManager {
!this.mainWindow.isVisible() &&
!this._floatingIconAutoHide
) {
- this.mainWindow.show();
+ this.showDictationPanel();
}
}, 10000);