RenaiApp/src/main.ts

59 lines
1.9 KiB
TypeScript

/* eslint-disable import/order -- this is the entry point for the application and some things have to happen before others */
import { app } from 'electron';
import { container, Service } from './main/core/container';
import './main/core/controller';
import { isDev } from './main/core/env';
import './main/core/install';
/**
* have a read: https://github.com/nodejs/node/issues/20392, over 100 comments as of 2020-07-26
* https://nodejs.org/api/process.html#process_event_unhandledrejection
*/
process.on('unhandledRejection', (reason) => {
const logger = container.get(Service.LOGGER);
void logger.fatal(`Unhandled Rejection, see ${logger.getExceptionsLogFile()}`);
throw reason;
});
process.on('uncaughtException', (error) => {
const logger = container.get(Service.LOGGER);
void logger.exception(error);
if (isDev()) {
// eslint-disable-next-line no-console -- only for development purposes
console.error(error);
}
});
async function createWindow(): Promise<void> {
const appWindowMain = container.get(Service.APP_WINDOW_MAIN);
await appWindowMain.open();
appWindowMain.window?.on('closed', () => {
app.quit();
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', () => {
void createWindow();
});
// Quit when all windows are closed.
app.on('window-all-closed', () => {
app.quit();
});
app.on('activate', () => {
// On OS X it"s common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
const appWindowMain = container.get(Service.APP_WINDOW_MAIN);
if (appWindowMain.isClosed()) {
void createWindow();
}
});
// In this file you can include the rest of your app"s specific main process
// code. You can also put them in separate files and require them here.