1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-14 23:33:19 +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 { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
import { AuthService } from 'jslib/abstractions/auth.service'; import { AuthService } from 'jslib/abstractions/auth.service';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { I18nService } from 'jslib/abstractions/i18n.service'; import { I18nService } from 'jslib/abstractions/i18n.service';
import { MessagingService } from 'jslib/abstractions/messaging.service'; import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.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 authService: AuthService, private router: Router, private analytics: Angulartics2,
private toasterService: ToasterService, private i18nService: I18nService, private toasterService: ToasterService, private i18nService: I18nService,
private platformUtilsService: PlatformUtilsService, private ngZone: NgZone, private platformUtilsService: PlatformUtilsService, private ngZone: NgZone,
private cryptoService: CryptoService, private componentFactoryResolver: ComponentFactoryResolver, private componentFactoryResolver: ComponentFactoryResolver, private messagingService: MessagingService) { }
private messagingService: MessagingService) { }
ngOnInit() { ngOnInit() {
this.ngZone.runOutsideAngular(() => { this.ngZone.runOutsideAngular(() => {
@@ -104,7 +102,6 @@ export class AppComponent implements OnInit {
private async updateAppMenu() { private async updateAppMenu() {
this.messagingService.send('updateAppMenu', { this.messagingService.send('updateAppMenu', {
isAuthenticated: await this.userService.isAuthenticated(), isAuthenticated: await this.userService.isAuthenticated(),
isLocked: (await this.cryptoService.getKey()) == null,
}); });
} }
@@ -113,7 +110,6 @@ export class AppComponent implements OnInit {
await Promise.all([ await Promise.all([
this.tokenService.clearToken(), this.tokenService.clearToken(),
this.cryptoService.clearKeys(),
this.userService.clear(), this.userService.clear(),
]); ]);

View File

@@ -51,8 +51,8 @@ export class Main {
this.storageService = new ElectronStorageService(); this.storageService = new ElectronStorageService();
this.windowMain = new WindowMain(this.storageService); this.windowMain = new WindowMain(this.storageService);
this.messagingMain = new MessagingMain(this.windowMain);
this.menuMain = new MenuMain(this); this.menuMain = new MenuMain(this);
this.messagingMain = new MessagingMain(this.windowMain, this.menuMain);
this.messagingService = new ElectronMainMessagingService(this.windowMain, (message) => { this.messagingService = new ElectronMainMessagingService(this.windowMain, (message) => {
this.messagingMain.onMessage(message); this.messagingMain.onMessage(message);
}); });

View File

@@ -13,16 +13,20 @@ import {
import { Main } from '../main'; import { Main } from '../main';
import { BaseMenu } from 'jslib/electron/baseMenu'; import { BaseMenu } from 'jslib/electron/baseMenu';
import { WindowMain } from 'jslib/electron/window.main';
import { ConstantsService } from 'jslib/services/constants.service'; 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 { export class MenuMain extends BaseMenu {
menu: Menu; menu: Menu;
logOut: MenuItem; logOut: MenuItem;
constructor(private main: Main) { constructor(main: Main) {
super(main.i18nService, main.windowMain, main.i18nService.t('bitwardenDirectoryConnector'), super(main.i18nService, main.windowMain, main.i18nService.t('bitwardenDirectoryConnector'),
() => this.main.messagingService.send('logout')); () => main.messagingService.send('logout'));
} }
init() { init() {
@@ -31,10 +35,10 @@ export class MenuMain extends BaseMenu {
this.initApplicationMenu(); this.initApplicationMenu();
this.logOut = this.menu.getMenuItemById('logOut'); 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; this.logOut.enabled = isAuthenticated;
} }
@@ -46,7 +50,7 @@ export class MenuMain extends BaseMenu {
}, },
this.editMenuItemOptions, this.editMenuItemOptions,
{ {
label: this.main.i18nService.t('view'), label: this.i18nService.t('view'),
submenu: this.viewSubMenuItemOptions, submenu: this.viewSubMenuItemOptions,
}, },
this.windowMenuItemOptions, this.windowMenuItemOptions,

View File

@@ -5,12 +5,14 @@ import {
import { WindowMain } from 'jslib/electron/window.main'; import { WindowMain } from 'jslib/electron/window.main';
import { MenuMain } from './menu.main';
const SyncInterval = 5 * 60 * 1000; // 5 minutes const SyncInterval = 5 * 60 * 1000; // 5 minutes
export class MessagingMain { export class MessagingMain {
private syncTimeout: NodeJS.Timer; private syncTimeout: NodeJS.Timer;
constructor(private windowMain: WindowMain) { } constructor(private windowMain: WindowMain, private menuMain: MenuMain) { }
init() { init() {
this.scheduleNextSync(); this.scheduleNextSync();
@@ -23,7 +25,7 @@ export class MessagingMain {
this.scheduleNextSync(); this.scheduleNextSync();
break; break;
case 'updateAppMenu': case 'updateAppMenu':
// this.main.menuMain.updateApplicationMenuState(message.isAuthenticated, message.isLocked); this.menuMain.updateApplicationMenuState(message.isAuthenticated);
break; break;
default: default:
break; break;