diff --git a/electron/main.js b/electron/main.js index 34cf7be99..428240071 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,7 +1,24 @@ /* eslint-disable no-process-exit */ /* eslint-disable @typescript-eslint/no-var-requires */ const { app, dialog, BrowserWindow, ipcMain, protocol } = require("electron"); + const log = require("electron-log"); +log.catchErrors(); + +// This handler must be set ASAP to prevent ghost processes. +process.on("uncaughtException", function () { + // The exception will be logged by electron-log. + app.quit(); + process.exit(1); +}); + +// This handler must be set ASAP to prevent ghost processes. +app.on("window-all-closed", () => { + log.info("Quitting the app..."); + app.quit(); + process.exit(0); +}); + const greenworks = require("./greenworks"); const api = require("./api-server"); const gameWindow = require("./gameWindow"); @@ -17,15 +34,8 @@ const { fileURLToPath } = require("url"); log.transports.file.level = store.get("file-log-level", "info"); log.transports.console.level = store.get("console-log-level", "debug"); -log.catchErrors(); log.info(`Started app: ${JSON.stringify(process.argv)}`); -process.on("uncaughtException", function () { - // The exception will already have been logged by electron-log - app.quit(); - process.exit(1); -}); - // We want to fail gracefully if we cannot connect to Steam try { if (greenworks && greenworks.init()) { @@ -42,13 +52,6 @@ try { let isRestoreDisabled = false; -// This was moved so that startup errors do not lead to ghost processes -app.on("window-all-closed", () => { - log.info("Quitting the app..."); - app.quit(); - process.exit(0); -}); - function setStopProcessHandler(app, window) { const closingWindowHandler = async (e) => { // We need to prevent the default closing event to add custom logic