diff --git a/app-shell-odd/src/main.ts b/app-shell-odd/src/main.ts index 7a65c5687ee..88ea6c78d9e 100644 --- a/app-shell-odd/src/main.ts +++ b/app-shell-odd/src/main.ts @@ -3,7 +3,7 @@ import { app, ipcMain } from 'electron' import dns from 'dns' import fse from 'fs-extra' import path from 'path' -import { createUi } from './ui' +import { createUi, waitForRobotServerAndShowMainWindow } from './ui' import { createLogger } from './log' import { registerDiscovery } from './discovery' import { @@ -122,10 +122,16 @@ function startUp(): void { log.silly('Global references', { mainWindow, rendererLogger }) ipcMain.once('dispatch', () => { + log.info('First dispatch, showing') systemd.sendStatus('started') systemd.ready() const stopWatching = watchForMassStorage(dispatch) ipcMain.once('quit', stopWatching) + if (!!!mainWindow) { + log.error('mainWindow went away before show') + } else { + waitForRobotServerAndShowMainWindow(dispatch, mainWindow) + } }) } diff --git a/app-shell-odd/src/ui.ts b/app-shell-odd/src/ui.ts index dce95f7f47e..f1bf84bad44 100644 --- a/app-shell-odd/src/ui.ts +++ b/app-shell-odd/src/ui.ts @@ -44,15 +44,7 @@ const WINDOW_OPTS = { export function createUi(dispatch: Dispatch): BrowserWindow { log.debug('Creating main window', { options: WINDOW_OPTS }) - const mainWindow = new BrowserWindow(WINDOW_OPTS).once( - 'ready-to-show', - () => { - log.debug('Main window ready to show') - mainWindow.show() - process.env.NODE_ENV !== 'development' && - waitForRobotServerAndShowMainWIndow(dispatch) - } - ) + const mainWindow = new BrowserWindow(WINDOW_OPTS) log.info(`Loading ${url}`) // eslint-disable-next-line @typescript-eslint/no-floating-promises @@ -66,19 +58,24 @@ export function createUi(dispatch: Dispatch): BrowserWindow { return mainWindow } -export function waitForRobotServerAndShowMainWIndow(dispatch: Dispatch): void { - setTimeout(function () { - systemd - .getisRobotServerReady() - .then((isReady: boolean) => { - dispatch(sendReadyStatus(isReady)) - if (!isReady) { - waitForRobotServerAndShowMainWIndow(dispatch) - } - }) - .catch(e => { - log.debug('Could not get status of robot server service', { e }) - waitForRobotServerAndShowMainWIndow(dispatch) - }) - }, 1500) +export function waitForRobotServerAndShowMainWindow( + dispatch: Dispatch, + mainWindow: BrowserWindow +): void { + mainWindow.show() + process.env.NODE_ENV !== 'development' && + setTimeout(function () { + systemd + .getisRobotServerReady() + .then((isReady: boolean) => { + dispatch(sendReadyStatus(isReady)) + if (!isReady) { + waitForRobotServerAndShowMainWindow(dispatch, mainWindow) + } + }) + .catch(e => { + log.debug('Could not get status of robot server service', { e }) + waitForRobotServerAndShowMainWindow(dispatch, mainWindow) + }) + }, 1500) }