diff --git a/src/main.ts b/src/main.ts index 1c80e2eb..31c5429a 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 48281663..82883bf3 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 8b335989..e42c7894 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; }