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 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);

View File

@ -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: () => {

View File

@ -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;
}