From b66e1e8c83d3fcb7dddda3cdbf6efd73ae802607 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 16 Feb 2018 09:59:03 -0500 Subject: [PATCH] null check windowMain.win --- src/main/menu.main.ts | 4 ++++ src/main/messaging.main.ts | 4 ++++ src/main/updater.main.ts | 11 ++++++++++- src/services/desktopMainMessaging.service.ts | 4 +++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/menu.main.ts b/src/main/menu.main.ts index ff267f1b3c..cb9278b72d 100644 --- a/src/main/menu.main.ts +++ b/src/main/menu.main.ts @@ -67,6 +67,10 @@ export class MenuMain { } private initContextMenu() { + if (this.main.windowMain.win == null) { + return; + } + const selectionMenu = Menu.buildFromTemplate([ { role: 'copy' }, { type: 'separator' }, diff --git a/src/main/messaging.main.ts b/src/main/messaging.main.ts index 33525bdafd..b706e80494 100644 --- a/src/main/messaging.main.ts +++ b/src/main/messaging.main.ts @@ -62,6 +62,10 @@ export class MessagingMain { } this.syncTimeout = global.setTimeout(() => { + if (this.main.windowMain.win == null) { + return; + } + this.main.windowMain.win.webContents.send('messagingService', { command: 'checkSyncVault', }); diff --git a/src/main/updater.main.ts b/src/main/updater.main.ts index 74fb1903d5..3c53566574 100644 --- a/src/main/updater.main.ts +++ b/src/main/updater.main.ts @@ -28,6 +28,11 @@ export class UpdaterMain { autoUpdater.on('update-available', () => { if (this.doingUpdateCheckWithFeedback) { + if (this.main.windowMain.win == null) { + this.reset(); + return; + } + const result = dialog.showMessageBox(this.main.windowMain.win, { type: 'info', title: this.main.i18nService.t('updateAvailable'), @@ -48,7 +53,7 @@ export class UpdaterMain { }); autoUpdater.on('update-not-available', () => { - if (this.doingUpdateCheckWithFeedback) { + if (this.doingUpdateCheckWithFeedback && this.main.windowMain.win != null) { dialog.showMessageBox(this.main.windowMain.win, { message: this.main.i18nService.t('noUpdatesAvailable'), }); @@ -60,6 +65,10 @@ export class UpdaterMain { autoUpdater.on('update-downloaded', (info) => { this.main.menuMain.updateMenuItem.label = this.main.i18nService.t('restartToUpdate'); + if (this.main.windowMain.win == null) { + return; + } + const result = dialog.showMessageBox(this.main.windowMain.win, { type: 'info', title: this.main.i18nService.t('restartToUpdate'), diff --git a/src/services/desktopMainMessaging.service.ts b/src/services/desktopMainMessaging.service.ts index fff5482344..8c5477058b 100644 --- a/src/services/desktopMainMessaging.service.ts +++ b/src/services/desktopMainMessaging.service.ts @@ -7,7 +7,9 @@ export class DesktopMainMessagingService implements MessagingService { send(subscriber: string, arg: any = {}) { const message = Object.assign({}, { command: subscriber }, arg); - this.main.windowMain.win.webContents.send('messagingService', message); this.main.messagingMain.onMessage(message); + if (this.main.windowMain.win != null) { + this.main.windowMain.win.webContents.send('messagingService', message); + } } }