diff --git a/app-shell-odd/electron-builder.config.js b/app-shell-odd/electron-builder.config.js index 8613efeb97d..d5cd4ac7eea 100644 --- a/app-shell-odd/electron-builder.config.js +++ b/app-shell-odd/electron-builder.config.js @@ -2,7 +2,7 @@ module.exports = { appId: 'com.opentrons.odd', - electronVersion: '23.3.13', + electronVersion: '27.0.0', npmRebuild: false, files: [ '**/*', diff --git a/app-shell-odd/src/main.ts b/app-shell-odd/src/main.ts index 7a65c5687ee..f536f56f96c 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,18 @@ 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) + // TODO: This is where we render the main window for the first time. See ui.ts + // in the createUI function for more. + 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..76e3dc6df36 100644 --- a/app-shell-odd/src/ui.ts +++ b/app-shell-odd/src/ui.ts @@ -44,15 +44,12 @@ 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) + // TODO: In the app, we immediately do .once('ready-to-show', () => { mainWindow.show() }). We don't do that + // here because in electron 27.0.0 for some reason ready-to-show isn't firing, so instead we use "the app sent + // something via IPC" as our signifier that the window can bw shown. This happens in main.ts. + // This is a worrying thing to have to do, and it would be good to stop doing it. We'll have to change this + // further when we upgrade past 27. log.info(`Loading ${url}`) // eslint-disable-next-line @typescript-eslint/no-floating-promises @@ -66,19 +63,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) }