get updater menu item by id

This commit is contained in:
Kyle Spearrin 2018-02-13 22:33:01 -05:00
parent f01f60b2db
commit c2043c1447
3 changed files with 17 additions and 14 deletions

View File

@ -30,13 +30,12 @@ const updaterMain = new UpdaterMain(windowMain, i18nService);
const menuMain = new MenuMain(windowMain, updaterMain, i18nService, messagingService); const menuMain = new MenuMain(windowMain, updaterMain, i18nService, messagingService);
const powerMonitorMain = new PowerMonitorMain(storageService, messagingService); const powerMonitorMain = new PowerMonitorMain(storageService, messagingService);
windowMain.init().then(() => { windowMain.init().then(async () => {
messagingMain.init(); messagingMain.init();
return i18nService.init(); await i18nService.init();
}).then(() => {
menuMain.init(); menuMain.init();
powerMonitorMain.init(); powerMonitorMain.init();
updaterMain.init(); await updaterMain.init();
}, (e: any) => { }, (e: any) => {
// tslint:disable-next-line // tslint:disable-next-line
console.log(e); console.log(e);

View File

@ -21,11 +21,6 @@ export class MenuMain {
private i18nService: I18nService, private messagingService: MessagingService) { } private i18nService: I18nService, private messagingService: MessagingService) { }
init() { init() {
this.updaterMain.updateMenuItem = {
label: this.i18nService.t('checkForUpdates'),
click: () => this.updaterMain.checkForUpdate(true),
};
const template: MenuItemConstructorOptions[] = [ const template: MenuItemConstructorOptions[] = [
{ {
label: this.i18nService.t('file'), 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') { if (process.platform === 'darwin') {
const firstMenuPart: MenuItemConstructorOptions[] = [ const firstMenuPart: MenuItemConstructorOptions[] = [
{ role: 'about' }, { role: 'about' },
this.updaterMain.updateMenuItem, updateMenuItem,
]; ];
template.unshift({ template.unshift({
@ -348,7 +349,7 @@ export class MenuMain {
template[template.length - 1].submenu = template[template.length - 1].submenu =
(template[template.length - 1].submenu as MenuItemConstructorOptions[]).concat([ (template[template.length - 1].submenu as MenuItemConstructorOptions[]).concat([
{ type: 'separator' }, { type: 'separator' },
this.updaterMain.updateMenuItem, updateMenuItem,
{ {
label: this.i18nService.t('about'), label: this.i18nService.t('about'),
click: () => { click: () => {

View File

@ -1,9 +1,11 @@
import { import {
dialog, dialog,
MenuItemConstructorOptions, Menu,
MenuItem,
} from 'electron'; } from 'electron';
import { autoUpdater } from 'electron-updater'; import { autoUpdater } from 'electron-updater';
import { isDev } from '../scripts/utils';
import { WindowMain } from './window.main'; import { WindowMain } from './window.main';
import { I18nService } from 'jslib/abstractions/i18n.service'; 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 const UpdaterCheckInterval = 12 * 60 * 60 * 1000; // 12 hours
export class UpdaterMain { export class UpdaterMain {
updateMenuItem: MenuItemConstructorOptions;
private doingUpdateCheck = false; private doingUpdateCheck = false;
private doingUpdateCheckWithFeedback = false; private doingUpdateCheckWithFeedback = false;
private updateMenuItem: MenuItem;
constructor(private windowMain: WindowMain, private i18nService: I18nService) { } constructor(private windowMain: WindowMain, private i18nService: I18nService) { }
async init() { async init() {
global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay); global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay);
global.setInterval(async () => await this.checkForUpdate(), UpdaterCheckInterval); global.setInterval(async () => await this.checkForUpdate(), UpdaterCheckInterval);
this.updateMenuItem = Menu.getApplicationMenu().getMenuItemById('checkForUpdates');
autoUpdater.on('checking-for-update', () => { autoUpdater.on('checking-for-update', () => {
this.updateMenuItem.enabled = false; this.updateMenuItem.enabled = false;
@ -89,7 +92,7 @@ export class UpdaterMain {
} }
async checkForUpdate(withFeedback: boolean = false) { async checkForUpdate(withFeedback: boolean = false) {
if (this.doingUpdateCheck) { if (this.doingUpdateCheck || isDev()) {
return; return;
} }