mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
Merge pull request #1962 from MartinFournier/feature/exit-process
Attempt to fix processes that stay up after closing app
This commit is contained in:
commit
c6843b231a
@ -7,11 +7,12 @@ if (greenworks.init()) {
|
||||
console.log("Steam API has failed to initialize.");
|
||||
}
|
||||
|
||||
console.log(greenworks.shutdown);
|
||||
|
||||
const debug = false;
|
||||
|
||||
let win = null;
|
||||
function createWindow(killall) {
|
||||
win = new BrowserWindow({
|
||||
const win = new BrowserWindow({
|
||||
show: false,
|
||||
backgroundThrottling: false,
|
||||
});
|
||||
@ -46,6 +47,7 @@ function createWindow(killall) {
|
||||
greenworks.activateAchievement(ach, () => undefined);
|
||||
}
|
||||
}, 1000);
|
||||
win.achievementsIntervalID = intervalID;
|
||||
|
||||
// Create the Application's main menu
|
||||
Menu.setApplicationMenu(
|
||||
@ -75,10 +77,11 @@ function createWindow(killall) {
|
||||
{
|
||||
label: "reload & kill all scripts",
|
||||
click: () => {
|
||||
setStopProcessHandler(app, win, false);
|
||||
if (intervalID) clearInterval(intervalID);
|
||||
createWindow(true);
|
||||
win.webContents.forcefullyCrashRenderer();
|
||||
win.close();
|
||||
createWindow(true);
|
||||
},
|
||||
},
|
||||
],
|
||||
@ -110,13 +113,35 @@ function createWindow(killall) {
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
return win;
|
||||
}
|
||||
|
||||
function setStopProcessHandler(app, window, enabled) {
|
||||
const clearWindowHandler = () => {
|
||||
if (window.achievementsIntervalID) {
|
||||
clearInterval(window.achievementsIntervalID);
|
||||
}
|
||||
window = null;
|
||||
};
|
||||
|
||||
const stopProcessHandler = () => {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
process.exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
if (enabled) {
|
||||
window.on("closed", clearWindowHandler);
|
||||
app.on("window-all-closed", stopProcessHandler);
|
||||
} else {
|
||||
window.removeListener("closed", clearWindowHandler);
|
||||
app.removeListener("window-all-closed", stopProcessHandler);
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createWindow(process.argv.includes("--no-scripts"));
|
||||
});
|
||||
|
||||
app.once("window-all-closed", app.quit);
|
||||
app.once("before-quit", () => {
|
||||
win.removeAllListeners("close");
|
||||
const win = createWindow(false);
|
||||
setStopProcessHandler(app, win, true);
|
||||
});
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user