refactor: ensure start order (#322)

This commit is contained in:
Carlos Valente
2023-04-03 11:10:51 +02:00
committed by GitHub
parent 32b5ab0574
commit b778835469
+16 -10
View File
@@ -29,14 +29,14 @@ let win;
let splash; let splash;
let tray = null; let tray = null;
(async () => { async function startBackend() {
await (async () => {
// 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) {
return; return;
} }
try { const ontimeServer = require(nodePath);
const ontimeServer = require(nodePath)
const { initAssets, startServer, startOSCServer, startIntegrations } = ontimeServer; const { initAssets, startServer, startOSCServer, startIntegrations } = ontimeServer;
await initAssets(); await initAssets();
@@ -44,10 +44,8 @@ let tray = null;
loaded = await startServer(); loaded = await startServer();
await startOSCServer(); await startOSCServer();
await startIntegrations(); await startIntegrations();
} catch (error) {
loaded = error;
}
})(); })();
}
/** /**
* @description utility function to create a notification * @description utility function to create a notification
@@ -158,12 +156,14 @@ app.whenReady().then(() => {
bringToFront(); bringToFront();
}); });
// cheat to schedule process startBackend()
setTimeout(() => { .then(() => {
// Load page served by node or use React dev run // Load page served by node or use React dev run
const clientUrl = isProduction ? electronConfig.reactAppUrl.production : electronConfig.reactAppUrl.development; const clientUrl = isProduction ? electronConfig.reactAppUrl.production : electronConfig.reactAppUrl.development;
win.loadURL(clientUrl).then(() => { win
.loadURL(clientUrl)
.then(() => {
win.webContents.setBackgroundThrottling(false); win.webContents.setBackgroundThrottling(false);
win.show(); win.show();
@@ -176,8 +176,14 @@ app.whenReady().then(() => {
} else { } else {
tray.setToolTip('Initialising error: please restart Ontime'); tray.setToolTip('Initialising error: please restart Ontime');
} }
})
.catch((error) => {
dialog.showErrorBox('Ontime failed to reach server', error);
});
})
.catch((error) => {
dialog.showErrorBox('Ontime failed to start', error);
}); });
}, 0);
// recreate window if no others open // recreate window if no others open
app.on('activate', () => { app.on('activate', () => {