Handle electron process uncaught exceptions

Handling the exceptions and closing the app seem to properly kill the
dangling processes that appear at launch in Windows 10. Without this, if
an exception is throw before the window is active (ie: no
steamapp_id.txt file), there will be remaining processes.

Added electron-log to additionally log to a text file.
This commit is contained in:
Martin Fournier
2021-12-20 06:33:46 -05:00
parent 9ea66e8743
commit 6363c704db
4 changed files with 40 additions and 10 deletions

View File

@@ -1,11 +1,21 @@
/* eslint-disable no-process-exit */
/* eslint-disable @typescript-eslint/no-var-requires */
const { app, BrowserWindow, Menu, shell, dialog } = require("electron");
const log = require('electron-log');
const greenworks = require("./greenworks");
log.catchErrors();
log.info(`Started app: ${JSON.stringify(process.argv)}`);
process.on('uncaughtException', function () {
// The exception will already have been logged by electron-log
process.exit(1);
});
if (greenworks.init()) {
console.log("Steam API has been initialized.");
log.info("Steam API has been initialized.");
} else {
console.log("Steam API has failed to initialize.");
log.warn("Steam API has failed to initialize.");
}
const debug = false;
@@ -67,6 +77,7 @@ function createWindow(killall) {
win.achievementsIntervalID = intervalID;
const reloadAndKill = (killScripts = true) => {
log.info('Reloading & Killing all scripts...');
setStopProcessHandler(app, win, false);
if (intervalID) clearInterval(intervalID);
win.webContents.forcefullyCrashRenderer();
@@ -168,8 +179,8 @@ function setStopProcessHandler(app, window, enabled) {
const stopProcessHandler = () => {
if (process.platform !== "darwin") {
log.info('Quitting the app...');
app.quit();
// eslint-disable-next-line no-process-exit
process.exit(0);
}
};
@@ -184,6 +195,7 @@ function setStopProcessHandler(app, window, enabled) {
}
app.whenReady().then(() => {
log.info('Application is ready!');
const win = createWindow(process.argv.includes("--no-scripts"));
setStopProcessHandler(app, win, true);
});