mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 14:59:16 +02:00
Merge branch 'dev' into mychanges
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
/* eslint-disable no-process-exit */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const { app, BrowserWindow, Menu, shell } = require("electron");
|
||||
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;
|
||||
@@ -66,6 +76,37 @@ function createWindow(killall) {
|
||||
}, 1000);
|
||||
win.achievementsIntervalID = intervalID;
|
||||
|
||||
const reloadAndKill = (killScripts = true) => {
|
||||
log.info('Reloading & Killing all scripts...');
|
||||
setStopProcessHandler(app, win, false);
|
||||
if (intervalID) clearInterval(intervalID);
|
||||
win.webContents.forcefullyCrashRenderer();
|
||||
win.close();
|
||||
createWindow(killScripts);
|
||||
};
|
||||
const promptForReload = () => {
|
||||
win.off('unresponsive', promptForReload);
|
||||
dialog.showMessageBox({
|
||||
type: 'error',
|
||||
title: 'Bitburner > Application Unresponsive',
|
||||
message: 'The application is unresponsive, possibly due to an infinite loop in your scripts.',
|
||||
detail:' Did you forget a ns.sleep(x)?\n\n' +
|
||||
'The application will be restarted for you, do you want to kill all running scripts?',
|
||||
buttons: ['Restart', 'Cancel'],
|
||||
defaultId: 0,
|
||||
checkboxLabel: 'Kill all running scripts',
|
||||
checkboxChecked: true,
|
||||
noLink: true,
|
||||
}).then(({response, checkboxChecked}) => {
|
||||
if (response === 0) {
|
||||
reloadAndKill(checkboxChecked);
|
||||
} else {
|
||||
win.on('unresponsive', promptForReload)
|
||||
}
|
||||
});
|
||||
}
|
||||
win.on('unresponsive', promptForReload);
|
||||
|
||||
// Create the Application's main menu
|
||||
Menu.setApplicationMenu(
|
||||
Menu.buildFromTemplate([
|
||||
@@ -93,13 +134,7 @@ function createWindow(killall) {
|
||||
},
|
||||
{
|
||||
label: "reload & kill all scripts",
|
||||
click: () => {
|
||||
setStopProcessHandler(app, win, false);
|
||||
if (intervalID) clearInterval(intervalID);
|
||||
win.webContents.forcefullyCrashRenderer();
|
||||
win.close();
|
||||
createWindow(true);
|
||||
},
|
||||
click: reloadAndKill
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -143,6 +178,7 @@ function setStopProcessHandler(app, window, enabled) {
|
||||
};
|
||||
|
||||
const stopProcessHandler = () => {
|
||||
log.info('Quitting the app...');
|
||||
app.isQuiting = true;
|
||||
app.quit();
|
||||
// eslint-disable-next-line no-process-exit
|
||||
@@ -159,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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user