Skip to content

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

fix: updated and cleaned up memory leaks when updating

Gabriel Stein2cef681633da
diff --git a/main.js b/main.js
index 5ddb3c79a..8f0f1763c 100644
--- a/main.js
+++ b/main.js
@@ -208,4 +208,5 @@ app.on("activate", () => {
app.on("will-quit", () => {
globalShortcut.unregisterAll();
globeKeyManager.stop();
+ updateManager.cleanup();
});
diff --git a/package.json b/package.json
index a37fc45c0..27fbc916a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "open-whispr",
- "version": "1.0.6",
+ "version": "1.0.4",
"description": "A desktop dictation application using OpenAI Whisper for speech-to-text transcription",
"main": "main.js",
"private": true,
diff --git a/preload.js b/preload.js
index 023c6f9f6..6ebaff045 100644
--- a/preload.js
+++ b/preload.js
@@ -76,6 +76,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
installUpdate: () => ipcRenderer.invoke("install-update"),
getAppVersion: () => ipcRenderer.invoke("get-app-version"),
getUpdateStatus: () => ipcRenderer.invoke("get-update-status"),
+ getUpdateInfo: () => ipcRenderer.invoke("get-update-info"),
// Update event listeners
onUpdateAvailable: (callback) => ipcRenderer.on("update-available", callback),
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index dce7dff1e..9234decba 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useCallback, useEffect } from "react";
+import React, { useState, useCallback, useEffect, useRef } from "react";
import { Button } from "./ui/button";
import { Input } from "./ui/input";
import { RefreshCw, Download, Keyboard, Mic, Shield } from "lucide-react";
@@ -17,6 +17,7 @@ import { formatHotkeyLabel } from "../utils/hotkeys";
import LanguageSelector from "./ui/LanguageSelector";
import PromptStudio from "./ui/PromptStudio";
import AIModelSelectorEnhanced from "./AIModelSelectorEnhanced";
+import type { UpdateInfoResult } from "../types/electron";
const InteractiveKeyboard = React.lazy(() => import("./ui/Keyboard"));
export type SettingsSectionType =
@@ -84,6 +85,7 @@ export default function SettingsPage({
}>({ updateAvailable: false, updateDownloaded: false, isDevelopment: false });
const [checkingForUpdates, setCheckingForUpdates] = useState(false);
const [downloadingUpdate, setDownloadingUpdate] = useState(false);
+ const [installInitiated, setInstallInitiated] = useState(false);
const [updateDownloadProgress, setUpdateDownloadProgress] = useState(0);
const [updateInfo, setUpdateInfo] = useState<{
version?: string;
@@ -96,10 +98,69 @@ export default function SettingsPage({
? "%USERPROFILE%\\.cache\\openwhispr\\models"
: "~/.cache/openwhispr/models";
+ const isUpdateAvailable =
+ !updateStatus.isDevelopment &&
+ (updateStatus.updateAvailable || updateStatus.updateDownloaded);
+
const whisperHook = useWhisper(showAlertDialog);
const permissionsHook = usePermissions(showAlertDialog);
const { pasteFromClipboardWithFallback } = useClipboard(showAlertDialog);
const { agentName, setAgentName } = useAgentName();
+ const installTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+
+ const subscribeToUpdates = useCallback(() => {
+ if (!window.electronAPI) return;
+
+ window.electronAPI.onUpdateAvailable?.((_event, info) => {
+ setUpdateStatus((prev) => ({ ...prev, updateAvailable: true, updateDownloaded: false }));
+ if (info) {
+ setUpdateInfo({
+ version: info.version || "unknown",
+ releaseDate: info.releaseDate,
+ releaseNotes: info.releaseNotes ?? undefined,
+ });
+ }
+ });
+
+ window.electronAPI.onUpdateNotAvailable?.(() => {
+ setUpdateStatus((prev) => ({ ...prev, updateAvailable: false, updateDownloaded: false }));
+ setUpdateInfo({});
+ setDownloadingUpdate(false);
+ setInstallInitiated(false);
+ setUpdateDownloadProgress(0);
+ });
+
+ window.electronAPI.onUpdateDownloaded?.((_event, info) => {
+ setUpdateStatus((prev) => ({ ...prev, updateDownloaded: true }));
+ setDownloadingUpdate(false);
+ setInstallInitiated(false);
+ if (info) {
+ setUpdateInfo({
+ version: info.version || "unknown",
+ releaseDate: info.releaseDate,
+ releaseNotes: info.releaseNotes ?? undefined,
+ });
+ }
+ });
+
+ window.electronAPI.onUpdateDownloadProgress?.((_event, progressObj) => {
+ setUpdateDownloadProgress(progressObj.percent || 0);
+ });
+
+ window.electronAPI.onUpdateError?.((_event, error) => {
+ setCheckingForUpdates(false);
+ setDownloadingUpdate(false);
+ setInstallInitiated(false);
+ console.error("Update error:", error);
+ showAlertDialog({
+ title: "Update Error",
+ description:
+ typeof error?.message === "string"
+ ? error.message
+ : "The updater encountered a problem. Please try again or download the latest release manually.",
+ });
+ });
+ }, [showAlertDialog]);
// Local state for provider selection (overrides computed value)
const [localReasoningProvider, setLocalReasoningProvider] = useState(() => {
@@ -113,26 +174,32 @@ export default function SettingsPage({
// Defer version and update checks to improve initial render
const timer = setTimeout(async () => {
if (!mounted) return;
-
+
const versionResult = await window.electronAPI?.getAppVersion();
if (versionResult && mounted) setCurrentVersion(versionResult.version);
const statusResult = await window.electronAPI?.getUpdateStatus();
if (statusResult && mounted) {
- setUpdateStatus(statusResult);
- if (statusResult.updateAvailable) {
- const updateInfoResult = await window.electronAPI?.getUpdateInfo?.();
- if (updateInfoResult) {
+ setUpdateStatus((prev) => ({
+ ...prev,
+ ...statusResult,
+ updateAvailable: prev.updateAvailable || statusResult.updateAvailable,
+ updateDownloaded: prev.updateDownloaded || statusResult.updateDownloaded,
+ }));
+ if ((statusResult.updateAvailable || statusResult.updateDownloaded) && window.electronAPI?.getUpdateInfo) {
+ const info = await window.electronAPI.getUpdateInfo();
+ if (info) {
setUpdateInfo({
- version: updateInfoResult.version || 'unknown',
- releaseDate: updateInfoResult.releaseDate,
- releaseNotes: updateInfoResult.releaseNotes,
+ version: info.version || "unknown",
+ releaseDate: info.releaseDate,
+ releaseNotes: info.releaseNotes ?? undefined,
});
}
}
- subscribeToUpdates();
}
+ subscribeToUpdates();
+
// Check whisper after initial render
if (mounted) {
whisperHook.checkWhisperInstallation();
@@ -145,47 +212,39 @@ export default function SettingsPage({
// Always clean up update listeners if they exist
if (window.electronAPI) {
window.electronAPI.removeAllListeners?.("update-available");
+ window.electronAPI.removeAllListeners?.("update-not-available");
window.electronAPI.removeAllListeners?.("update-downloaded");
window.electronAPI.removeAllListeners?.("update-error");
window.electronAPI.removeAllListeners?.("update-download-progress");
}
};
- }, [whisperHook]);
-
- const subscribeToUpdates = () => {
- if (window.electronAPI) {
- const handleUpdateAvailable = (event, info) => {
- setUpdateStatus((prev) => ({ ...prev, updateAvailable: true, updateDownloaded: false }));
- if (info) {
- setUpdateInfo({
- version: info.version || 'unknown',
- releaseDate: info.releaseDate,
- releaseNotes: info.releaseNotes,
- });
- }
- };
-
- const handleUpdateDownloaded = (event, info) => {
- setUpdateStatus((prev) => ({ ...prev, updateDownloaded: true }));
- setDownloadingUpdate(false);
- };
-
- const handleUpdateProgress = (event, progressObj) => {
- setUpdateDownloadProgress(progressObj.percent || 0);
- };
-
- const handleUpdateError = (event, error) => {
- setCheckingForUpdates(false);
- setDownloadingUpdate(false);
- console.error("Update error:", error);
- };
-
- window.electronAPI.onUpdateAvailable?.(handleUpdateAvailable);
- window.electronAPI.onUpdateDownloaded?.(handleUpdateDownloaded);
- window.electronAPI.onUpdateDownloadProgress?.(handleUpdateProgress);
- window.electronAPI.onUpdateError?.(handleUpdateError);
+ }, [whisperHook, subscribeToUpdates]);
+
+ useEffect(() => {
+ if (installInitiated) {
+ if (installTimeoutRef.current) {
+ clearTimeout(installTimeoutRef.current);
+ }
+ installTimeoutRef.current = setTimeout(() => {
+ setInstallInitiated(false);
+ showAlertDialog({
+ title: "Still Running",
+ description:
+ "OpenWhispr didn't restart automatically. Please quit the app manually to finish installing the update.",
+ });
+ }, 10000);
+ } else if (installTimeoutRef.current) {
+ clearTimeout(installTimeoutRef.current);
+ installTimeoutRef.current = null;
}
- };
+
+ return () => {
+ if (installTimeoutRef.current) {
+ clearTimeout(installTimeoutRef.current);
+ installTimeoutRef.current = null;
+ }
+ };
+ }, [installInitiated, showAlertDialog]);
const saveReasoningSettings = useCallback(async () => {
// Update reasoning settings
@@ -486,48 +545,83 @@ export default function SettingsPage({
)}
</Button>
- {updateStatus.updateAvailable && !updateStatus.updateDownloaded && (
- <Button
- onClick={async () => {
- setDownloadingUpdate(true);
- setUpdateDownloadProgress(0);
- try {
- await window.electronAPI?.downloadUpdate();
- } catch (error: any) {
- setDownloadingUpdate(false);
- showAlertDialog({
- title: "Download Failed",
- description: `Failed to download update: ${error.message}`,
- });
- }
- }}
- disabled={downloadingUpdate}
- className="w-full bg-green-600 hover:bg-green-700"
- >
- {downloadingUpdate ? (
- <>
- <Download size={16} className="animate-pulse mr-2" />
- Downloading... {Math.round(updateDownloadProgress)}%
- </>
- ) : (
- <>
- <Download size={16} className="mr-2" />
- Download Update{updateInfo.version ? ` v${updateInfo.version}` : ''}
- </>
+ {isUpdateAvailable && !updateStatus.updateDownloaded && (
+ <div className="space-y-2">
+ <Button
+ onClick={async () => {
+ setDownloadingUpdate(true);
+ setUpdateDownloadProgress(0);
+ try {
+ await window.electronAPI?.downloadUpdate();
+ } catch (error: any) {
+ setDownloadingUpdate(false);
+ showAlertDialog({
+ title: "Download Failed",
+ description: `Failed to download update: ${error.message}`,
+ });
+ }
+ }}
+ disabled={downloadingUpdate}
+ className="w-full bg-green-600 hover:bg-green-700"
+ >
+ {downloadingUpdate ? (
+ <>
+ <Download size={16} className="animate-pulse mr-2" />
+ Downloading... {Math.round(updateDownloadProgress)}%
+ </>
+ ) : (
+ <>
+ <Download size={16} className="mr-2" />
+ Download Update{updateInfo.version ? ` v${updateInfo.version}` : ''}
+ </>
+ )}
+ </Button>
+
+ {downloadingUpdate && (
+ <div className="space-y-1">
+ <div className="h-2 w-full overflow-hidden rounded-full bg-neutral-200">
+ <div
+ className="h-full bg-green-600 transition-all duration-200"
+ style={{ width: `${Math.min(100, Math.max(0, updateDownloadProgress))}%` }}
+ />
+ </div>
+ <p className="text-xs text-neutral-600 text-right">
+ {Math.round(updateDownloadProgress)}% downloaded
+ </p>
+ </div>
)}
- </Button>
+ </div>
)}
{updateStatus.updateDownloaded && (
<Button
- onClick={async () => {
+ onClick={() => {
showConfirmDialog({
title: "Install Update",
description: `Ready to install update${updateInfo.version ? ` v${updateInfo.version}` : ''}. The app will restart to complete installation.`,
+ confirmText: "Install & Restart",
onConfirm: async () => {
try {
- await window.electronAPI?.installUpdate();
+ setInstallInitiated(true);
+ const result = await window.electronAPI?.installUpdate?.();
+ if (!result?.success) {
+ setInstallInitiated(false);
+ showAlertDialog({
+ title: "Install Failed",
+ description:
+ result?.message ||
+ "Failed to start the installer. Please try again.",
+ });
+ return;
+ }
+
+ showAlertDialog({
+ title: "Installing Update",
+ description:
+ "OpenWhispr will restart automatically to finish installing the newest version.",
+ });
} catch (error: any) {
+ setInstallInitiated(false);
showAlertDialog({
title: "Install Failed",
description: `Failed to install update: ${error.message}`,
@@ -536,10 +630,20 @@ export default function SettingsPage({
},
});
}}
+ disabled={installInitiated}
className="w-full bg-blue-600 hover:bg-blue-700"
>
- <span className="mr-2">πŸš€</span>
- Install Update & Restart
+ {installInitiated ? (
+ <>
+ <RefreshCw size={16} className="animate-spin mr-2" />
+ Restarting to Finish Update...
+ </>
+ ) : (
+ <>
+ <span className="mr-2">πŸš€</span>
+ Quit & Install Update
+ </>
+ )}
</Button>
)}
diff --git a/src/types/electron.ts b/src/types/electron.ts
index 1c2c77647..20344854d 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -54,6 +54,13 @@ export interface UpdateStatusResult {
isDevelopment: boolean;
}
+export interface UpdateInfoResult {
+ version?: string;
+ releaseDate?: string;
+ releaseNotes?: string | null;
+ files?: any[];
+}
+
export interface UpdateResult {
success: boolean;
message: string;
@@ -219,6 +226,7 @@ declare global {
installUpdate: () => Promise<UpdateResult>;
getAppVersion: () => Promise<AppVersionResult>;
getUpdateStatus: () => Promise<UpdateStatusResult>;
+ getUpdateInfo: () => Promise<UpdateInfoResult | null>;
// Update event listeners
onUpdateAvailable: (callback: (event: any, info: any) => void) => void;
diff --git a/src/updater.js b/src/updater.js
index 147d78833..fd0c35fcd 100644
--- a/src/updater.js
+++ b/src/updater.js
@@ -7,6 +7,12 @@ class UpdateManager {
this.controlPanelWindow = null;
this.updateAvailable = false;
this.updateDownloaded = false;
+ this.lastUpdateInfo = null;
+ this.isInstalling = false;
+ this.isDownloading = false;
+ this.installTimeout = null;
+ this.ipcHandlers = [];
+ this.eventListeners = [];
this.setupAutoUpdater();
this.setupIPCHandlers();
@@ -32,163 +38,240 @@ class UpdateManager {
private: false,
});
- autoUpdater.logger = null;
+ // Disable auto-download - let user control when to download
+ autoUpdater.autoDownload = false;
+ autoUpdater.autoInstallOnAppQuit = false;
+
+ // Enable logging in production for debugging (logs are user-accessible)
+ autoUpdater.logger = console;
// Set up event handlers
this.setupEventHandlers();
}
setupEventHandlers() {
- autoUpdater.on("checking-for-update", () => {});
-
- autoUpdater.on("update-available", (info) => {
- this.updateAvailable = true;
-
- this.notifyRenderers("update-available", info);
- });
-
- autoUpdater.on("update-not-available", (info) => {
- this.updateAvailable = false;
-
- this.notifyRenderers("update-not-available", info);
- });
-
- autoUpdater.on("error", (err) => {
- console.error("❌ Auto-updater error:", err);
- this.updateAvailable = false;
- this.updateDownloaded = false;
-
- this.notifyRenderers("update-error", err);
- });
-
- autoUpdater.on("download-progress", (progressObj) => {
- this.notifyRenderers("update-download-progress", progressObj);
- });
-
- autoUpdater.on("update-downloaded", (info) => {
- this.updateDownloaded = true;
+ const handlers = {
+ "checking-for-update": () => {
+ this.notifyRenderers("checking-for-update");
+ },
+ "update-available": (info) => {
+ this.updateAvailable = true;
+ if (info) {
+ this.lastUpdateInfo = {
+ version: info.version,
+ releaseDate: info.releaseDate,
+ releaseNotes: info.releaseNotes,
+ files: info.files,
+ };
+ }
+ this.notifyRenderers("update-available", info);
+ },
+ "update-not-available": (info) => {
+ this.updateAvailable = false;
+ this.updateDownloaded = false;
+ this.isDownloading = false;
+ this.lastUpdateInfo = null;
+ this.notifyRenderers("update-not-available", info);
+ },
+ "error": (err) => {
+ console.error("❌ Auto-updater error:", err);
+ this.isDownloading = false;
+ this.notifyRenderers("update-error", err);
+ },
+ "download-progress": (progressObj) => {
+ this.notifyRenderers("update-download-progress", progressObj);
+ },
+ "update-downloaded": (info) => {
+ this.updateDownloaded = true;
+ this.isDownloading = false;
+ if (info) {
+ this.lastUpdateInfo = {
+ version: info.version,
+ releaseDate: info.releaseDate,
+ releaseNotes: info.releaseNotes,
+ files: info.files,
+ };
+ }
+ this.notifyRenderers("update-downloaded", info);
+ }
+ };
- this.notifyRenderers("update-downloaded", info);
+ // Register and track event listeners for cleanup
+ Object.entries(handlers).forEach(([event, handler]) => {
+ autoUpdater.on(event, handler);
+ this.eventListeners.push({ event, handler });
});
}
notifyRenderers(channel, data) {
- if (this.mainWindow && this.mainWindow.webContents) {
+ if (this.mainWindow && !this.mainWindow.isDestroyed() && this.mainWindow.webContents) {
this.mainWindow.webContents.send(channel, data);
}
- if (this.controlPanelWindow && this.controlPanelWindow.webContents) {
+ if (this.controlPanelWindow && !this.controlPanelWindow.isDestroyed() && this.controlPanelWindow.webContents) {
this.controlPanelWindow.webContents.send(channel, data);
}
}
setupIPCHandlers() {
- // Check for updates manually
- ipcMain.handle("check-for-updates", async () => {
- try {
- if (process.env.NODE_ENV === "development") {
- return {
- updateAvailable: false,
- message: "Update checks are disabled in development mode",
- };
+ const handlers = [
+ {
+ channel: "check-for-updates",
+ handler: async () => {
+ try {
+ if (process.env.NODE_ENV === "development") {
+ return {
+ updateAvailable: false,
+ message: "Update checks are disabled in development mode",
+ };
+ }
+
+ const result = await autoUpdater.checkForUpdates();
+
+ if (result && result.updateInfo) {
+ console.log("πŸ“‹ Update check result:", result.updateInfo);
+ return {
+ updateAvailable: true,
+ version: result.updateInfo.version,
+ releaseDate: result.updateInfo.releaseDate,
+ files: result.updateInfo.files,
+ releaseNotes: result.updateInfo.releaseNotes,
+ };
+ } else {
+ return {
+ updateAvailable: false,
+ message: "You are running the latest version",
+ };
+ }
+ } catch (error) {
+ console.error("❌ Update check error:", error);
+ throw error;
+ }
}
-
- const result = await autoUpdater.checkForUpdates();
-
- if (result && result.updateInfo) {
- console.log("πŸ“‹ Update check result:", result.updateInfo);
- return {
- updateAvailable: true,
- version: result.updateInfo.version,
- releaseDate: result.updateInfo.releaseDate,
- files: result.updateInfo.files,
- releaseNotes: result.updateInfo.releaseNotes,
- };
- } else {
- return {
- updateAvailable: false,
- message: "You are running the latest version",
- };
+ },
+ {
+ channel: "download-update",
+ handler: async () => {
+ try {
+ if (process.env.NODE_ENV === "development") {
+ return {
+ success: false,
+ message: "Update downloads are disabled in development mode",
+ };
+ }
+
+ if (this.isDownloading) {
+ return {
+ success: false,
+ message: "Download already in progress",
+ };
+ }
+
+ if (this.updateDownloaded) {
+ return {
+ success: false,
+ message: "Update already downloaded. Ready to install.",
+ };
+ }
+
+ this.isDownloading = true;
+ await autoUpdater.downloadUpdate();
+
+ return { success: true, message: "Update download started" };
+ } catch (error) {
+ this.isDownloading = false;
+ console.error("❌ Update download error:", error);
+ throw error;
+ }
}
- } catch (error) {
- console.error("❌ Update check error:", error);
- throw error;
- }
- });
-
- // Download update
- ipcMain.handle("download-update", async () => {
- try {
- if (process.env.NODE_ENV === "development") {
- return {
- success: false,
- message: "Update downloads are disabled in development mode",
- };
+ },
+ {
+ channel: "install-update",
+ handler: async () => {
+ try {
+ if (process.env.NODE_ENV === "development") {
+ return {
+ success: false,
+ message: "Update installation is disabled in development mode",
+ };
+ }
+
+ if (!this.updateDownloaded) {
+ return {
+ success: false,
+ message: "No update available to install",
+ };
+ }
+
+ if (this.isInstalling) {
+ return {
+ success: false,
+ message: "Update installation already in progress",
+ };
+ }
+
+ this.isInstalling = true;
+ console.log("πŸ”„ Installing update and restarting...");
+
+ this.installTimeout = setTimeout(() => {
+ autoUpdater.quitAndInstall(false, false);
+ }, 100);
+
+ return { success: true, message: "Update installation started" };
+ } catch (error) {
+ this.isInstalling = false;
+ if (this.installTimeout) {
+ clearTimeout(this.installTimeout);
+ this.installTimeout = null;
+ }
+ console.error("❌ Update installation error:", error);
+ throw error;
+ }
}
-
- await autoUpdater.downloadUpdate();
-
- return { success: true, message: "Update download started" };
- } catch (error) {
- console.error("❌ Update download error:", error);
- throw error;
- }
- });
-
- // Install update
- ipcMain.handle("install-update", async () => {
- try {
- if (process.env.NODE_ENV === "development") {
- console.log("⚠️ Update installation skipped in development mode");
- return {
- success: false,
- message: "Update installation is disabled in development mode",
- };
+ },
+ {
+ channel: "get-app-version",
+ handler: async () => {
+ try {
+ const { app } = require("electron");
+ return { version: app.getVersion() };
+ } catch (error) {
+ console.error("❌ Error getting app version:", error);
+ throw error;
+ }
}
-
- if (!this.updateDownloaded) {
- console.error("❌ No update downloaded to install");
- return {
- success: false,
- message: "No update available to install",
- };
+ },
+ {
+ channel: "get-update-status",
+ handler: async () => {
+ try {
+ return {
+ updateAvailable: this.updateAvailable,
+ updateDownloaded: this.updateDownloaded,
+ isDevelopment: process.env.NODE_ENV === "development",
+ };
+ } catch (error) {
+ console.error("❌ Error getting update status:", error);
+ throw error;
+ }
+ }
+ },
+ {
+ channel: "get-update-info",
+ handler: async () => {
+ try {
+ return this.lastUpdateInfo;
+ } catch (error) {
+ console.error("❌ Error getting update info:", error);
+ throw error;
+ }
}
-
- console.log("πŸ”„ Installing update and restarting...");
-
- // Use setImmediate to ensure the response is sent before quitting
- setImmediate(() => {
- autoUpdater.quitAndInstall();
- });
-
- return { success: true, message: "Update installation started" };
- } catch (error) {
- console.error("❌ Update installation error:", error);
- throw error;
- }
- });
-
- ipcMain.handle("get-app-version", async () => {
- try {
- const { app } = require("electron");
- const version = app.getVersion();
- return { version };
- } catch (error) {
- console.error("❌ Error getting app version:", error);
- throw error;
}
- });
+ ];
- ipcMain.handle("get-update-status", async () => {
- try {
- return {
- updateAvailable: this.updateAvailable,
- updateDownloaded: this.updateDownloaded,
- isDevelopment: process.env.NODE_ENV === "development",
- };
- } catch (error) {
- console.error("❌ Error getting update status:", error);
- throw error;
- }
+ // Register all handlers and track for cleanup
+ handlers.forEach(({ channel, handler }) => {
+ ipcMain.handle(channel, handler);
+ this.ipcHandlers.push({ channel, handler });
});
}
@@ -198,10 +281,33 @@ class UpdateManager {
// Wait a bit for the app to fully initialize
setTimeout(() => {
console.log("πŸ”„ Checking for updates on startup...");
- autoUpdater.checkForUpdatesAndNotify();
- }, 5000);
+ autoUpdater.checkForUpdates().catch(err => {
+ console.error("Startup update check failed:", err);
+ });
+ }, 3000); // Reduced from 5s to 3s for better UX
}
}
+
+ // Cleanup method to be called on app quit
+ cleanup() {
+ // Clear timeout
+ if (this.installTimeout) {
+ clearTimeout(this.installTimeout);
+ this.installTimeout = null;
+ }
+
+ // Remove event listeners
+ this.eventListeners.forEach(({ event, handler }) => {
+ autoUpdater.removeListener(event, handler);
+ });
+ this.eventListeners = [];
+
+ // Remove IPC handlers
+ this.ipcHandlers.forEach(({ channel }) => {
+ ipcMain.removeHandler(channel);
+ });
+ this.ipcHandlers = [];
+ }
}
module.exports = UpdateManager;