Skip to content

Commit

Permalink
show mainwindow after first browser dispatch
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sfoster1 committed Mar 18, 2024
1 parent 4a86047 commit 7228a25
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
8 changes: 7 additions & 1 deletion app-shell-odd/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
})
}

Expand Down
45 changes: 21 additions & 24 deletions app-shell-odd/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

0 comments on commit 7228a25

Please sign in to comment.