From b0705a911d3863fb3a75c1d0b9b0d6a3f2947e16 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 26 Apr 2018 16:00:47 -0400 Subject: [PATCH] wire up message service to menu --- src/app/app.component.ts | 6 +----- src/main.ts | 2 +- src/main/menu.main.ts | 14 +++++++++----- src/main/messaging.main.ts | 6 ++++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 0c83b463..b3c1f566 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -24,7 +24,6 @@ import { ModalComponent } from 'jslib/angular/components/modal.component'; import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; import { AuthService } from 'jslib/abstractions/auth.service'; -import { CryptoService } from 'jslib/abstractions/crypto.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { MessagingService } from 'jslib/abstractions/messaging.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; @@ -63,8 +62,7 @@ export class AppComponent implements OnInit { private authService: AuthService, private router: Router, private analytics: Angulartics2, private toasterService: ToasterService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private ngZone: NgZone, - private cryptoService: CryptoService, private componentFactoryResolver: ComponentFactoryResolver, - private messagingService: MessagingService) { } + private componentFactoryResolver: ComponentFactoryResolver, private messagingService: MessagingService) { } ngOnInit() { this.ngZone.runOutsideAngular(() => { @@ -104,7 +102,6 @@ export class AppComponent implements OnInit { private async updateAppMenu() { this.messagingService.send('updateAppMenu', { isAuthenticated: await this.userService.isAuthenticated(), - isLocked: (await this.cryptoService.getKey()) == null, }); } @@ -113,7 +110,6 @@ export class AppComponent implements OnInit { await Promise.all([ this.tokenService.clearToken(), - this.cryptoService.clearKeys(), this.userService.clear(), ]); diff --git a/src/main.ts b/src/main.ts index b328d6d8..67a4a095 100644 --- a/src/main.ts +++ b/src/main.ts @@ -51,8 +51,8 @@ export class Main { this.storageService = new ElectronStorageService(); this.windowMain = new WindowMain(this.storageService); - this.messagingMain = new MessagingMain(this.windowMain); this.menuMain = new MenuMain(this); + this.messagingMain = new MessagingMain(this.windowMain, this.menuMain); this.messagingService = new ElectronMainMessagingService(this.windowMain, (message) => { this.messagingMain.onMessage(message); }); diff --git a/src/main/menu.main.ts b/src/main/menu.main.ts index 77a8f838..1a920854 100644 --- a/src/main/menu.main.ts +++ b/src/main/menu.main.ts @@ -13,16 +13,20 @@ import { import { Main } from '../main'; import { BaseMenu } from 'jslib/electron/baseMenu'; +import { WindowMain } from 'jslib/electron/window.main'; import { ConstantsService } from 'jslib/services/constants.service'; +import { I18nService } from 'jslib/abstractions/i18n.service'; +import { MessagingService } from 'jslib/abstractions/messaging.service'; + export class MenuMain extends BaseMenu { menu: Menu; logOut: MenuItem; - constructor(private main: Main) { + constructor(main: Main) { super(main.i18nService, main.windowMain, main.i18nService.t('bitwardenDirectoryConnector'), - () => this.main.messagingService.send('logout')); + () => main.messagingService.send('logout')); } init() { @@ -31,10 +35,10 @@ export class MenuMain extends BaseMenu { this.initApplicationMenu(); this.logOut = this.menu.getMenuItemById('logOut'); - this.updateApplicationMenuState(false, true); + this.updateApplicationMenuState(false); } - updateApplicationMenuState(isAuthenticated: boolean, isLocked: boolean) { + updateApplicationMenuState(isAuthenticated: boolean) { this.logOut.enabled = isAuthenticated; } @@ -46,7 +50,7 @@ export class MenuMain extends BaseMenu { }, this.editMenuItemOptions, { - label: this.main.i18nService.t('view'), + label: this.i18nService.t('view'), submenu: this.viewSubMenuItemOptions, }, this.windowMenuItemOptions, diff --git a/src/main/messaging.main.ts b/src/main/messaging.main.ts index b07cc7a6..bb15a7d4 100644 --- a/src/main/messaging.main.ts +++ b/src/main/messaging.main.ts @@ -5,12 +5,14 @@ import { import { WindowMain } from 'jslib/electron/window.main'; +import { MenuMain } from './menu.main'; + const SyncInterval = 5 * 60 * 1000; // 5 minutes export class MessagingMain { private syncTimeout: NodeJS.Timer; - constructor(private windowMain: WindowMain) { } + constructor(private windowMain: WindowMain, private menuMain: MenuMain) { } init() { this.scheduleNextSync(); @@ -23,7 +25,7 @@ export class MessagingMain { this.scheduleNextSync(); break; case 'updateAppMenu': - // this.main.menuMain.updateApplicationMenuState(message.isAuthenticated, message.isLocked); + this.menuMain.updateApplicationMenuState(message.isAuthenticated); break; default: break;