get updater menu item by id
This commit is contained in:
parent
f01f60b2db
commit
c2043c1447
|
@ -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);
|
||||
|
|
|
@ -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: () => {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue