From dc21a5b87bced9a8eb2ba5553fdc5fef4c367156 Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Thu, 16 Dec 2021 18:26:20 -0500 Subject: [PATCH] Attempt to fix processes that stay up after closing app --- electron/main.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/electron/main.js b/electron/main.js index 622676967..f155f1d54 100644 --- a/electron/main.js +++ b/electron/main.js @@ -9,12 +9,22 @@ if (greenworks.init()) { const debug = false; +let win; +let intervalID; + function createWindow(killall) { - const win = new BrowserWindow({ + win = new BrowserWindow({ show: false, backgroundThrottling: false, }); + win.on('closed', function() { + clearInterval(intervalID); + win = null; + app.quit(); + process.exit(0); + }); + win.removeMenu(); win.maximize(); noScripts = killall ? { query: { noScripts: killall } } : {}; @@ -37,7 +47,7 @@ function createWindow(killall) { // This is backward but the game fills in an array called `document.achievements` and we retrieve it from // here. Hey if it works it works. const achievements = greenworks.getAchievementNames(); - const intervalID = setInterval(async () => { + intervalID = setInterval(async () => { const achs = await win.webContents.executeJavaScript("document.achievements"); console.log(achs); for (const ach of achs) { @@ -111,6 +121,17 @@ function createWindow(killall) { ); } +app.on('window-all-closed', function () { + // On OS X it is common for applications and their menu bar + // to stay active until the user quits explicitly with Cmd + Q + if (process.platform !== 'darwin') { + clearInterval(intervalID); + win = null; + app.quit() + process.exit(0); + } +}); + app.whenReady().then(() => { createWindow(false); });