From 7228a250106336b749cd3a20572502c4dc744033 Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Mon, 18 Mar 2024 15:29:25 -0400 Subject: [PATCH] show mainwindow after first browser dispatch We used to show mainWindow on the ready-to-show event. For some reason that's just not happening anymore, but everything underneath is actually working fine. Instead, we can show when we get the first dispatch from the app side. This may lead to us spending more time on the pre-app splash and less tim on the spinner. --- app-shell-odd/src/main.ts | 8 ++++++- app-shell-odd/src/ui.ts | 45 ++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 25 deletions(-) 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) }