Skip to content

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

fix: defer debugLogger file initialization until app.whenReady() (#141)

Gabriel Stein3440d1870288
diff --git a/main.js b/main.js
index 8a703889f..cd8979e05 100644
--- a/main.js
+++ b/main.js
@@ -85,6 +85,10 @@ function initializeManagers() {
// Now it's safe to call app.getPath() and initialize managers
debugLogger = require("./src/helpers/debugLogger");
+ // IMPORTANT: Ensure file logging is initialized now that app is ready
+ // This is necessary because debugLogger may have been loaded before app.whenReady()
+ // via transitive imports (e.g., windowManager -> hotkeyManager -> debugLogger)
+ debugLogger.ensureFileLogging();
environmentManager = new EnvironmentManager();
debugLogger.refreshLogLevel();
windowManager = new WindowManager();
diff --git a/src/helpers/debugLogger.js b/src/helpers/debugLogger.js
index d37932902..17636f98e 100644
--- a/src/helpers/debugLogger.js
+++ b/src/helpers/debugLogger.js
@@ -39,15 +39,23 @@ class DebugLogger {
this.logFile = null;
this.logStream = null;
this.fileLoggingEnabled = false;
+ this.fileLoggingPending = this.debugMode; // Track if we need to initialize file logging later
- if (this.debugMode) {
- this.initializeFileLogging();
- }
+ // IMPORTANT: Do NOT call initializeFileLogging() here!
+ // It uses app.getPath() which is unsafe before app.whenReady().
+ // File logging will be initialized on first log write or via ensureFileLogging().
}
initializeFileLogging() {
if (this.fileLoggingEnabled) return;
+ // Check if app is ready before accessing app.getPath()
+ // This is critical because app.getPath() can hang or fail before app.whenReady()
+ if (!app.isReady()) {
+ // App not ready yet, will try again later via ensureFileLogging() or write()
+ return;
+ }
+
try {
const logsDir = path.join(app.getPath("userData"), "logs");
if (!fs.existsSync(logsDir)) {
@@ -59,6 +67,7 @@ class DebugLogger {
this.logStream = fs.createWriteStream(this.logFile, { flags: "a" });
this.fileLoggingEnabled = true;
+ this.fileLoggingPending = false;
this.debug("Debug logging enabled", { logFile: this.logFile });
this.info("System Info", {
@@ -72,10 +81,21 @@ class DebugLogger {
});
} catch (error) {
this.fileLoggingEnabled = false;
+ this.fileLoggingPending = false;
console.error("Failed to initialize debug logging:", error);
}
}
+ /**
+ * Ensures file logging is initialized if debug mode is enabled.
+ * This should be called after app.whenReady() to safely initialize file logging.
+ */
+ ensureFileLogging() {
+ if (this.fileLoggingPending && !this.fileLoggingEnabled) {
+ this.initializeFileLogging();
+ }
+ }
+
resolveLogLevel() {
const argLevel = normalizeLevel(readArgLogLevel());
if (argLevel) {
@@ -145,6 +165,11 @@ class DebugLogger {
const normalized = normalizeLevel(level) || "info";
if (!this.shouldLog(normalized)) return;
+ // Try to initialize file logging if pending and app is ready
+ if (this.fileLoggingPending && !this.fileLoggingEnabled) {
+ this.initializeFileLogging();
+ }
+
const timestamp = new Date().toISOString();
const scopeTag = scope ? `[${scope}]` : "";
const sourceTag = source ? `[${source}]` : "";