cordis/client/main.ts

72 lines
2.0 KiB
TypeScript
Raw Normal View History

2021-10-30 17:26:41 +00:00
import Logger from '../logger/logger';
2021-11-02 04:29:24 +00:00
const LOG = Logger.create(__filename);
2021-10-30 17:26:41 +00:00
2021-10-31 19:02:26 +00:00
LOG.silly('main begins');
2021-10-30 17:26:41 +00:00
import * as path from 'path';
import * as electron from 'electron';
import { ExitCodes, ExitCode } from '../exit-codes/exit-codes';
process.on('unhandledRejection', async (reason: any, _promise: Promise<any>) => {
LOG.fatal('unhandled promise rejection:', reason);
ExitCodes.exit(ExitCode.GENERAL_ERROR);
});
// Initialize electron remote so that we can get console logs all in the same place
import * as electronMain from '@electron/remote/main';
LOG.silly('modules loaded');
2021-10-30 17:26:41 +00:00
electronMain.initialize();
(async () => {
await electron.app.whenReady();
LOG.silly('electron app is ready');
2021-11-07 20:13:59 +00:00
await LOG.ensureSourceMaps();
LOG.silly('base log source maps loaded');
2021-12-03 03:42:02 +00:00
const display = electron.screen.getPrimaryDisplay();
let width = 1580;//1080
let height = 720;
let x = display.workArea.x + display.workAreaSize.width / 2 - width / 2;
let y = display.workArea.y + display.workAreaSize.height / 2 - height / 2;
2021-10-30 17:26:41 +00:00
const window = new electron.BrowserWindow({
2021-12-03 03:42:02 +00:00
width: width,
height: height,
x: x,
y: y,
2021-10-30 17:26:41 +00:00
minWidth: 940,
minHeight: 500,
frame: false,
title: 'cordis',
webPreferences: {
//@ts-ignore enableRemoteModule is enabled with @electron/remote and not included in electron's typing
enableRemoteModule: true, // so we can get console logs properly
preload: path.join(__dirname, 'webapp', 'preload.js')
2021-10-30 17:26:41 +00:00
}
});
window.loadFile(path.join(__dirname, 'webapp', 'index.html'));
electronMain.enable(window.webContents);
window.webContents.openDevTools();
electron.ipcMain.on('minimize', () => {
window.minimize();
});
electron.ipcMain.on('maximize', () => {
window.maximize();
});
electron.ipcMain.on('close', () => {
window.close();
});
})();