From c2043c14475d92cd23ed9c986d5452b7283ddd0d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 13 Feb 2018 22:33:01 -0500 Subject: [PATCH] get updater menu item by id --- src/main.ts | 7 +++---- src/main/menu.main.ts | 15 ++++++++------- src/main/updater.main.ts | 9 ++++++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1c80e2ebe8..31c5429a87 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,13 +30,12 @@ const updaterMain = new UpdaterMain(windowMain, i18nService); const menuMain = new MenuMain(windowMain, updaterMain, i18nService, messagingService); const powerMonitorMain = new PowerMonitorMain(storageService, messagingService); -windowMain.init().then(() => { +windowMain.init().then(async () => { messagingMain.init(); - return i18nService.init(); -}).then(() => { + await i18nService.init(); menuMain.init(); powerMonitorMain.init(); - updaterMain.init(); + await updaterMain.init(); }, (e: any) => { // tslint:disable-next-line console.log(e); diff --git a/src/main/menu.main.ts b/src/main/menu.main.ts index 4828166366..82883bf364 100644 --- a/src/main/menu.main.ts +++ b/src/main/menu.main.ts @@ -21,11 +21,6 @@ export class MenuMain { private i18nService: I18nService, private messagingService: MessagingService) { } init() { - this.updaterMain.updateMenuItem = { - label: this.i18nService.t('checkForUpdates'), - click: () => this.updaterMain.checkForUpdate(true), - }; - const template: MenuItemConstructorOptions[] = [ { label: this.i18nService.t('file'), @@ -311,10 +306,16 @@ export class MenuMain { }, ]; + const updateMenuItem = { + label: this.i18nService.t('checkForUpdates'), + click: () => this.updaterMain.checkForUpdate(true), + id: 'checkForUpdates', + }; + if (process.platform === 'darwin') { const firstMenuPart: MenuItemConstructorOptions[] = [ { role: 'about' }, - this.updaterMain.updateMenuItem, + updateMenuItem, ]; template.unshift({ @@ -348,7 +349,7 @@ export class MenuMain { template[template.length - 1].submenu = (template[template.length - 1].submenu as MenuItemConstructorOptions[]).concat([ { type: 'separator' }, - this.updaterMain.updateMenuItem, + updateMenuItem, { label: this.i18nService.t('about'), click: () => { diff --git a/src/main/updater.main.ts b/src/main/updater.main.ts index 8b33598912..e42c789452 100644 --- a/src/main/updater.main.ts +++ b/src/main/updater.main.ts @@ -1,9 +1,11 @@ import { dialog, - MenuItemConstructorOptions, + Menu, + MenuItem, } from 'electron'; import { autoUpdater } from 'electron-updater'; +import { isDev } from '../scripts/utils'; import { WindowMain } from './window.main'; import { I18nService } from 'jslib/abstractions/i18n.service'; @@ -12,16 +14,17 @@ const UpdaterCheckInitalDelay = 5 * 1000; // 5 seconds const UpdaterCheckInterval = 12 * 60 * 60 * 1000; // 12 hours export class UpdaterMain { - updateMenuItem: MenuItemConstructorOptions; private doingUpdateCheck = false; private doingUpdateCheckWithFeedback = false; + private updateMenuItem: MenuItem; constructor(private windowMain: WindowMain, private i18nService: I18nService) { } async init() { global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay); global.setInterval(async () => await this.checkForUpdate(), UpdaterCheckInterval); + this.updateMenuItem = Menu.getApplicationMenu().getMenuItemById('checkForUpdates'); autoUpdater.on('checking-for-update', () => { this.updateMenuItem.enabled = false; @@ -89,7 +92,7 @@ export class UpdaterMain { } async checkForUpdate(withFeedback: boolean = false) { - if (this.doingUpdateCheck) { + if (this.doingUpdateCheck || isDev()) { return; }