Merge branch 'dev' into mychanges

This commit is contained in:
hydroflame
2021-12-22 16:16:24 -05:00
committed by GitHub
17 changed files with 933 additions and 179 deletions

View File

@@ -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);
});