Skip to content

Commit

Permalink
Add checks for isDestroyed on window shows (#1723)
Browse files Browse the repository at this point in the history
* Add checks for isdestroyed

* more checks

* Update src/main/gui/splash.ts

Co-authored-by: Michael Schmidt <mitchi5000.ms@googlemail.com>

---------

Co-authored-by: Michael Schmidt <mitchi5000.ms@googlemail.com>
  • Loading branch information
joeyballentine and RunDevelopment committed Apr 9, 2023
1 parent 1140512 commit 04ba6fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/main/gui/main-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@ export const createMainWindow = async (args: OpenArguments) => {
ipcMain.once('backend-ready', () => {
progressController.submitProgress({ totalProgress: 1 });

if (mainWindow.isDestroyed()) {
dialog.showMessageBoxSync({
type: 'error',
title: 'Unable to start application',
message: 'The main window was closed before the backend was ready.',
});
app.quit();
return;
}

mainWindow.show();
if (lastWindowSize?.maximized) {
mainWindow.maximize();
Expand Down
9 changes: 6 additions & 3 deletions src/main/gui/splash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ export const addSplashScreen = (monitor: ProgressMonitor) => {
}, 100);

splash.once('ready-to-show', () => {
splash.show();
if (!splash.isDestroyed()) {
splash.show();
}
});

monitor.addProgressListener((progress) => {
lastProgress = { ...progress };
splash.webContents.send('splash-setup-progress', progress);

if (progress.totalProgress === 1) {
progressFinished = true;
Expand All @@ -80,7 +81,9 @@ export const addSplashScreen = (monitor: ProgressMonitor) => {

let messageBoxOptions: MessageBoxOptions;
if (interrupt.type === 'critical error') {
splash.hide();
if (!splash.isDestroyed()) {
splash.hide();
}

messageBoxOptions = {
type: 'error',
Expand Down

0 comments on commit 04ba6fe

Please sign in to comment.