mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-09 17:23:53 +01:00
63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
const { app, BrowserWindow } = require("electron");
|
|
const log = require("electron-log");
|
|
const utils = require("./utils");
|
|
const achievements = require("./achievements");
|
|
const menu = require("./menu");
|
|
const api = require("./api-server");
|
|
const cp = require("child_process");
|
|
|
|
const debug = process.argv.includes("--debug");
|
|
|
|
async function createWindow(killall) {
|
|
const setStopProcessHandler = global.app_handlers.stopProcess;
|
|
const window = new BrowserWindow({
|
|
show: false,
|
|
backgroundThrottling: false,
|
|
backgroundColor: "#000000",
|
|
});
|
|
|
|
window.removeMenu();
|
|
window.maximize();
|
|
noScripts = killall ? { query: { noScripts: killall } } : {};
|
|
window.loadFile("index.html", noScripts);
|
|
window.show();
|
|
if (debug) window.webContents.openDevTools();
|
|
|
|
window.webContents.on("new-window", function (e, url) {
|
|
if (process.platform === "win32") {
|
|
cp.spawn("explorer", [url], { detached: true, stdio: "ignore" });
|
|
} else {
|
|
// make sure local urls stay in electron perimeter
|
|
if (url.substr(0, "file://".length) === "file://") {
|
|
return;
|
|
}
|
|
|
|
// and open every other protocols on the browser
|
|
utils.openExternal(url);
|
|
}
|
|
e.preventDefault();
|
|
});
|
|
window.webContents.backgroundThrottling = false;
|
|
|
|
achievements.enableAchievementsInterval(window);
|
|
utils.attachUnresponsiveAppHandler(window);
|
|
utils.setZoomFactor(window);
|
|
|
|
try {
|
|
await api.initialize(window);
|
|
} catch (error) {
|
|
log.error(error);
|
|
utils.showErrorBox("Error starting http server", error);
|
|
}
|
|
|
|
menu.refreshMenu(window);
|
|
setStopProcessHandler(app, window, true);
|
|
|
|
return window;
|
|
}
|
|
|
|
module.exports = {
|
|
createWindow,
|
|
};
|