From 75f2f3dded4d36c4ae9f7c127f5bb7e9522276c6 Mon Sep 17 00:00:00 2001 From: Michael Hollister Date: Tue, 29 Apr 2025 12:17:29 -0500 Subject: [PATCH] Electron: Added null checks before sending window messages --- receivers/electron/src/Main.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/receivers/electron/src/Main.ts b/receivers/electron/src/Main.ts index 64df2ff..7fce58e 100644 --- a/receivers/electron/src/Main.ts +++ b/receivers/electron/src/Main.ts @@ -36,7 +36,7 @@ export class Main { private static async checkForUpdates(silent: boolean) { if (Updater.updateDownloaded) { - Main.mainWindow.webContents.send("download-complete"); + Main.mainWindow?.webContents?.send("download-complete"); return; } @@ -44,7 +44,7 @@ export class Main { const updateAvailable = await Updater.checkForUpdates(); if (updateAvailable) { - Main.mainWindow.webContents.send("update-available"); + Main.mainWindow?.webContents?.send("update-available"); } else { if (!silent) { @@ -232,7 +232,7 @@ export class Main { if (!Updater.isDownloading) { try { await Updater.downloadUpdate(); - Main.mainWindow.webContents.send("download-complete"); + Main.mainWindow?.webContents?.send("download-complete"); } catch (err) { await dialog.showMessageBox({ type: 'error', @@ -243,7 +243,7 @@ export class Main { }); Main.logger.error('Failed to download update:', err); - Main.mainWindow.webContents.send("download-failed"); + Main.mainWindow?.webContents?.send("download-failed"); } } }); @@ -299,7 +299,7 @@ export class Main { Main.checkForUpdates(true); } - Main.mainWindow.webContents.setWindowOpenHandler((details) => { + Main.mainWindow?.webContents?.setWindowOpenHandler((details) => { shell.openExternal(details.url); return { action: "deny" }; }); @@ -339,7 +339,7 @@ export class Main { }); ipcMain.on('network-changed', (event: IpcMainEvent, value: any) => { - Main.mainWindow.webContents.send("device-info", { name: os.hostname(), interfaces: value }); + Main.mainWindow?.webContents?.send("device-info", { name: os.hostname(), interfaces: value }); }); networkWorker.loadFile(path.join(__dirname, 'main/worker.html')); }); @@ -449,7 +449,7 @@ export function getComputerName() { export async function errorHandler(err: NodeJS.ErrnoException) { Main.logger.error("Application error:", err); - Main.mainWindow.webContents.send("toast", { message: err, icon: ToastIcon.ERROR }); + Main.mainWindow?.webContents?.send("toast", { message: err, icon: ToastIcon.ERROR }); const restartPrompt = await dialog.showMessageBox({ type: 'error',