Skip to content

Commit

Permalink
Ensure we only handle dom-ready once (#771)
Browse files Browse the repository at this point in the history
* Remove get-port listener if exists

* make sure dom-ready only ever fires once

* remove handler fix
  • Loading branch information
joeyballentine authored Aug 19, 2022
1 parent c4eefdc commit b91cd5b
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,30 +549,43 @@ const doSplashScreenChecks = async () =>
// Send events to splash screen renderer as they happen
// Added some sleep functions so I can see that this is doing what I want it to
// TODO: Remove the sleeps (or maybe not, since it feels more like something is happening here)
splash.webContents.once('dom-ready', async () => {
splash.webContents.send('checking-port');
const port = await getValidPort(splash);
await sleep(250);
const trueOnce = (fn: () => void): (() => void) => {
let first = true;
return () => {
if (first) {
first = false;
fn();
}
};
};

splash.webContents.send('checking-python');
await checkPythonEnv(splash);
await sleep(250);
splash.webContents.once(
'dom-ready',
trueOnce(async () => {
splash.webContents.send('checking-port');
const port = await getValidPort(splash);
await sleep(250);

splash.webContents.send('checking-deps');
await checkPythonDeps(splash);
await checkNvidiaSmi();
await sleep(250);
splash.webContents.send('checking-python');
await checkPythonEnv(splash);
await sleep(250);

splash.webContents.send('spawning-backend');
await spawnBackend(port);
splash.webContents.send('checking-deps');
await checkPythonDeps(splash);
await checkNvidiaSmi();
await sleep(250);

registerEventHandlers();
splash.webContents.send('spawning-backend');
await spawnBackend(port);

splash.webContents.send('splash-finish');
await sleep(250);
registerEventHandlers();

resolve();
});
splash.webContents.send('splash-finish');
await sleep(250);

resolve();
})
);

ipcMain.once('backend-ready', async () => {
splash.webContents.send('finish-loading');
Expand Down

0 comments on commit b91cd5b

Please sign in to comment.