Attempt to fix processes that stay up after closing app

This commit is contained in:
Martin Fournier 2021-12-16 18:26:20 -05:00
parent 3436873373
commit dc21a5b87b

@ -9,12 +9,22 @@ if (greenworks.init()) {
const debug = false; const debug = false;
let win;
let intervalID;
function createWindow(killall) { function createWindow(killall) {
const win = new BrowserWindow({ win = new BrowserWindow({
show: false, show: false,
backgroundThrottling: false, backgroundThrottling: false,
}); });
win.on('closed', function() {
clearInterval(intervalID);
win = null;
app.quit();
process.exit(0);
});
win.removeMenu(); win.removeMenu();
win.maximize(); win.maximize();
noScripts = killall ? { query: { noScripts: killall } } : {}; 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 // 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. // here. Hey if it works it works.
const achievements = greenworks.getAchievementNames(); const achievements = greenworks.getAchievementNames();
const intervalID = setInterval(async () => { intervalID = setInterval(async () => {
const achs = await win.webContents.executeJavaScript("document.achievements"); const achs = await win.webContents.executeJavaScript("document.achievements");
console.log(achs); console.log(achs);
for (const ach of 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(() => { app.whenReady().then(() => {
createWindow(false); createWindow(false);
}); });