mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-24 08:29:14 +00:00
refactor: escalate severe to electron
This commit is contained in:
committed by
Carlos Valente
parent
d41cd78f2e
commit
8742b790f3
@@ -41,7 +41,7 @@ async function startBackend() {
|
|||||||
|
|
||||||
await initAssets();
|
await initAssets();
|
||||||
|
|
||||||
const result = await startServer();
|
const result = await startServer(escalateError);
|
||||||
loaded = result.message;
|
loaded = result.message;
|
||||||
|
|
||||||
await startIntegrations();
|
await startIntegrations();
|
||||||
@@ -86,6 +86,11 @@ function askToQuit() {
|
|||||||
win.send('user-request-shutdown');
|
win.send('user-request-shutdown');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escalateError(error) {
|
||||||
|
dialog.showErrorBox('An unrecoverable error occurred', error);
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure there isn't another instance of the app running already
|
// Ensure there isn't another instance of the app running already
|
||||||
const lock = app.requestSingleInstanceLock();
|
const lock = app.requestSingleInstanceLock();
|
||||||
if (!lock) {
|
if (!lock) {
|
||||||
@@ -213,11 +218,8 @@ app.whenReady().then(() => {
|
|||||||
const trayMenuTemplate = getTrayMenu(bringToFront, askToQuit);
|
const trayMenuTemplate = getTrayMenu(bringToFront, askToQuit);
|
||||||
const trayContextMenu = Menu.buildFromTemplate(trayMenuTemplate);
|
const trayContextMenu = Menu.buildFromTemplate(trayMenuTemplate);
|
||||||
tray.setContextMenu(trayContextMenu);
|
tray.setContextMenu(trayContextMenu);
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// unregister shortcuts before quitting
|
// unregister shortcuts before quitting
|
||||||
app.once('will-quit', () => {
|
app.once('will-quit', () => {
|
||||||
globalShortcut.unregisterAll();
|
globalShortcut.unregisterAll();
|
||||||
|
|||||||
@@ -153,9 +153,10 @@ export const initAssets = async () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts servers
|
* Starts servers
|
||||||
* @return {Promise<string>}
|
|
||||||
*/
|
*/
|
||||||
export const startServer = async () => {
|
export const startServer = async (
|
||||||
|
escalateErrorFn?: (error: string) => void,
|
||||||
|
): Promise<{ message: string; serverPort: number }> => {
|
||||||
checkStart(OntimeStartOrder.InitServer);
|
checkStart(OntimeStartOrder.InitServer);
|
||||||
|
|
||||||
const { serverPort } = DataProvider.getSettings();
|
const { serverPort } = DataProvider.getSettings();
|
||||||
@@ -185,6 +186,9 @@ export const startServer = async () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// initialise logging service, escalateErrorFn is only exists in electron
|
||||||
|
logger.init(escalateErrorFn);
|
||||||
|
|
||||||
// initialise rundown service
|
// initialise rundown service
|
||||||
const persistedRundown = DataProvider.getRundown();
|
const persistedRundown = DataProvider.getRundown();
|
||||||
const persistedCustomFields = DataProvider.getCustomFields();
|
const persistedCustomFields = DataProvider.getCustomFields();
|
||||||
|
|||||||
@@ -8,19 +8,26 @@ import { consoleRed } from '../utils/console.js';
|
|||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
private queue: Log[];
|
private queue: Log[];
|
||||||
|
private escalateErrorFn: (error: string) => void | null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.queue = [];
|
this.queue = [];
|
||||||
|
this.escalateErrorFn = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enabling setup logger after init
|
* Enabling setup logger after init
|
||||||
*/
|
*/
|
||||||
init() {
|
init(escalateErrorFn: (error: string) => void) {
|
||||||
this.queue.forEach((log) => {
|
this.queue.forEach((log) => {
|
||||||
this._push(log);
|
this._push(log);
|
||||||
});
|
});
|
||||||
this.queue = [];
|
this.queue = [];
|
||||||
|
|
||||||
|
// we only get this when running in electron
|
||||||
|
if (escalateErrorFn) {
|
||||||
|
this.escalateErrorFn = escalateErrorFn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private addToQueue(log: Log) {
|
private addToQueue(log: Log) {
|
||||||
@@ -105,6 +112,7 @@ class Logger {
|
|||||||
*/
|
*/
|
||||||
crash(origin: string, text: string) {
|
crash(origin: string, text: string) {
|
||||||
this.emit(LogLevel.Severe, origin, text);
|
this.emit(LogLevel.Severe, origin, text);
|
||||||
|
this.escalateErrorFn?.(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user