2021-12-29 14:46:56 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2022-01-03 16:29:56 +01:00
|
|
|
const { app, 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");
|
|
|
|
|
|
|
|
const debug = process.argv.includes("--debug");
|
|
|
|
|
|
|
|
async function createWindow(killall) {
|
2021-12-30 15:07:31 +01:00
|
|
|
const setStopProcessHandler = global.app_handlers.stopProcess
|
2021-12-29 14:46:56 +01:00
|
|
|
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) {
|
|
|
|
// make sure local urls stay in electron perimeter
|
|
|
|
if (url.substr(0, "file://".length) === "file://") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// and open every other protocols on the browser
|
|
|
|
e.preventDefault();
|
2022-01-03 16:29:56 +01:00
|
|
|
utils.openExternal(url);
|
2021-12-29 14:46:56 +01:00
|
|
|
});
|
|
|
|
window.webContents.backgroundThrottling = false;
|
|
|
|
|
|
|
|
achievements.enableAchievementsInterval(window);
|
|
|
|
utils.attachUnresponsiveAppHandler(window);
|
2022-01-05 03:08:06 +01:00
|
|
|
utils.setZoomFactor(window);
|
2021-12-29 14:46:56 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
await api.initialize(window);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
utils.showErrorBox('Error starting http server', error);
|
|
|
|
}
|
|
|
|
|
|
|
|
menu.refreshMenu(window);
|
2021-12-30 15:07:31 +01:00
|
|
|
setStopProcessHandler(app, window, true);
|
2021-12-29 14:46:56 +01:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
createWindow,
|
|
|
|
}
|