2021-12-29 14:46:56 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2023-02-25 23:42:26 +01:00
|
|
|
const { app, shell, BrowserWindow } = require("electron");
|
2021-12-29 14:46:56 +01:00
|
|
|
const log = require("electron-log");
|
|
|
|
const utils = require("./utils");
|
|
|
|
const achievements = require("./achievements");
|
|
|
|
const menu = require("./menu");
|
|
|
|
const api = require("./api-server");
|
2022-01-11 16:52:14 +01:00
|
|
|
const path = require("path");
|
2022-01-23 14:41:09 +01:00
|
|
|
const { windowTracker } = require("./windowTracker");
|
2021-12-29 14:46:56 +01:00
|
|
|
|
|
|
|
const debug = process.argv.includes("--debug");
|
|
|
|
|
|
|
|
async function createWindow(killall) {
|
2022-01-09 20:02:11 +01:00
|
|
|
const setStopProcessHandler = global.app_handlers.stopProcess;
|
2022-04-07 01:30:08 +02:00
|
|
|
app.setAppUserModelId("Bitburner");
|
2022-01-23 18:38:47 +01:00
|
|
|
|
|
|
|
let icon;
|
2022-04-07 01:30:08 +02:00
|
|
|
if (process.platform == "linux") {
|
|
|
|
icon = path.join(__dirname, "icon.png");
|
2022-01-23 18:38:47 +01:00
|
|
|
}
|
|
|
|
|
2022-04-07 01:30:08 +02:00
|
|
|
const tracker = windowTracker("main");
|
2021-12-29 14:46:56 +01:00
|
|
|
const window = new BrowserWindow({
|
2022-01-23 18:38:47 +01:00
|
|
|
icon,
|
2021-12-29 14:46:56 +01:00
|
|
|
show: false,
|
|
|
|
backgroundThrottling: false,
|
|
|
|
backgroundColor: "#000000",
|
2022-04-07 01:30:08 +02:00
|
|
|
title: "Bitburner",
|
2022-01-23 14:41:09 +01:00
|
|
|
x: tracker.state.x,
|
|
|
|
y: tracker.state.y,
|
|
|
|
width: tracker.state.width,
|
|
|
|
height: tracker.state.height,
|
|
|
|
minWidth: 600,
|
|
|
|
minHeight: 400,
|
2022-01-23 18:40:28 +01:00
|
|
|
webPreferences: {
|
|
|
|
nativeWindowOpen: true,
|
2022-04-07 01:30:08 +02:00
|
|
|
preload: path.join(__dirname, "preload.js"),
|
2022-01-23 18:40:28 +01:00
|
|
|
},
|
2021-12-29 14:46:56 +01:00
|
|
|
});
|
|
|
|
|
2022-01-23 14:41:09 +01:00
|
|
|
setTimeout(() => tracker.track(window), 1000);
|
|
|
|
if (tracker.state.isMaximized) window.maximize();
|
|
|
|
|
2021-12-29 14:46:56 +01:00
|
|
|
window.removeMenu();
|
|
|
|
noScripts = killall ? { query: { noScripts: killall } } : {};
|
|
|
|
window.loadFile("index.html", noScripts);
|
2024-05-06 19:13:56 +02:00
|
|
|
window.once("ready-to-show", () => {
|
|
|
|
utils.setZoomFactor(window, utils.getZoomFactor());
|
|
|
|
});
|
2021-12-29 14:46:56 +01:00
|
|
|
window.show();
|
|
|
|
if (debug) window.webContents.openDevTools();
|
|
|
|
|
2023-02-25 23:42:26 +01:00
|
|
|
window.webContents.setWindowOpenHandler(({ url }) => {
|
|
|
|
// File protocol is allowed because it will use the file protocol intercept from main.js
|
|
|
|
if (url.startsWith("file://")) return { action: "allow" };
|
|
|
|
// Only http and https requests will be forwarded to browser.
|
|
|
|
// By using shell.openExternal and returning action: "deny"
|
|
|
|
if (url.startsWith("http://") || url.startsWith("https://")) shell.openExternal(url);
|
|
|
|
return { action: "deny" };
|
2021-12-29 14:46:56 +01:00
|
|
|
});
|
2023-02-25 23:42:26 +01:00
|
|
|
|
2021-12-29 14:46:56 +01:00
|
|
|
window.webContents.backgroundThrottling = false;
|
|
|
|
|
|
|
|
achievements.enableAchievementsInterval(window);
|
|
|
|
utils.attachUnresponsiveAppHandler(window);
|
|
|
|
|
|
|
|
try {
|
|
|
|
await api.initialize(window);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
2022-01-09 20:02:11 +01:00
|
|
|
utils.showErrorBox("Error starting http server", error);
|
2021-12-29 14:46:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
menu.refreshMenu(window);
|
2023-01-11 01:12:23 +01:00
|
|
|
setStopProcessHandler(app, window);
|
2021-12-29 14:46:56 +01:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
createWindow,
|
2022-01-09 20:02:11 +01:00
|
|
|
};
|