1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-05 23:53:21 +00:00

wire up message service to menu

This commit is contained in:
Kyle Spearrin
2018-04-26 16:00:47 -04:00
parent 99c7f619e0
commit b0705a911d
4 changed files with 15 additions and 13 deletions

View File

@@ -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(),
]);

View File

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

View File

@@ -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,

View File

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