mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-27 09:59:08 +00:00
chore: document aux functions
This commit is contained in:
committed by
Carlos Valente
parent
8742b790f3
commit
4f672670ed
+35
-6
@@ -30,6 +30,10 @@ let win;
|
|||||||
let splash;
|
let splash;
|
||||||
let tray = null;
|
let tray = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coordinates the node process startup
|
||||||
|
* @returns {number} server port - the port at which the backend has been started at
|
||||||
|
*/
|
||||||
async function startBackend() {
|
async function startBackend() {
|
||||||
// in dev mode, we expect both UI and server to be running
|
// in dev mode, we expect both UI and server to be running
|
||||||
if (!isProduction) {
|
if (!isProduction) {
|
||||||
@@ -62,6 +66,9 @@ function showNotification(title, text) {
|
|||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terminate node service and close electron app
|
||||||
|
*/
|
||||||
function appShutdown() {
|
function appShutdown() {
|
||||||
// terminate node service
|
// terminate node service
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -76,19 +83,28 @@ function appShutdown() {
|
|||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets Ontime window in focus
|
||||||
|
*/
|
||||||
function bringToFront() {
|
function bringToFront() {
|
||||||
win.show();
|
win.show();
|
||||||
win.focus();
|
win.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coordinates the shutdown process
|
||||||
|
*/
|
||||||
function askToQuit() {
|
function askToQuit() {
|
||||||
bringToFront();
|
bringToFront();
|
||||||
win.send('user-request-shutdown');
|
win.send('user-request-shutdown');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows processes to escalate errors to be shown in electron
|
||||||
|
* @param {string} error
|
||||||
|
*/
|
||||||
function escalateError(error) {
|
function escalateError(error) {
|
||||||
dialog.showErrorBox('An unrecoverable error occurred', 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
|
||||||
@@ -108,6 +124,9 @@ if (!lock) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coordinates creation of electron windows (splash and main)
|
||||||
|
*/
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
splash = new BrowserWindow({
|
splash = new BrowserWindow({
|
||||||
width: 333,
|
width: 333,
|
||||||
@@ -196,12 +215,16 @@ app.whenReady().then(() => {
|
|||||||
console.log('ERROR: Ontime failed to start', error);
|
console.log('ERROR: Ontime failed to start', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
// recreate window if no others open
|
/**
|
||||||
|
* recreate window if no others open
|
||||||
|
*/
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
win.show();
|
win.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Hide on close
|
/**
|
||||||
|
* Hide on close
|
||||||
|
*/
|
||||||
win.on('close', function (event) {
|
win.on('close', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (!isQuitting) {
|
if (!isQuitting) {
|
||||||
@@ -220,7 +243,9 @@ app.whenReady().then(() => {
|
|||||||
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();
|
||||||
});
|
});
|
||||||
@@ -237,7 +262,9 @@ ipcMain.on('shutdown', () => {
|
|||||||
appShutdown();
|
appShutdown();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Window manipulation
|
/**
|
||||||
|
* Handles requests to set window properties
|
||||||
|
*/
|
||||||
ipcMain.on('set-window', (event, arg) => {
|
ipcMain.on('set-window', (event, arg) => {
|
||||||
switch (arg) {
|
switch (arg) {
|
||||||
case 'show-dev':
|
case 'show-dev':
|
||||||
@@ -248,7 +275,9 @@ ipcMain.on('set-window', (event, arg) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Open links external
|
/**
|
||||||
|
* Handles requests to open external links
|
||||||
|
*/
|
||||||
ipcMain.on('send-to-link', (event, arg) => {
|
ipcMain.on('send-to-link', (event, arg) => {
|
||||||
shell.openExternal(arg);
|
shell.openExternal(arg);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class Logger {
|
|||||||
* Enabling setup logger after init
|
* Enabling setup logger after init
|
||||||
*/
|
*/
|
||||||
init(escalateErrorFn: (error: string) => void) {
|
init(escalateErrorFn: (error: string) => void) {
|
||||||
|
// flush logs from queue
|
||||||
this.queue.forEach((log) => {
|
this.queue.forEach((log) => {
|
||||||
this._push(log);
|
this._push(log);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user