1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

abstract MessagingService

This commit is contained in:
Kyle Spearrin
2018-01-04 16:06:00 -05:00
parent 0fbbc4a0b9
commit d39c5b37dc
10 changed files with 51 additions and 23 deletions

View File

@@ -265,8 +265,9 @@ angular
}
const userService = trans.injector().get('userService');
const messagingService = trans.injector().get('messagingService');
if (!userService) {
if (!userService || !messagingService) {
return;
}
@@ -278,7 +279,7 @@ angular
}
else if (toState.data && toState.data.authorize) {
event.preventDefault();
chrome.runtime.sendMessage({ command: 'logout' });
messagingService.send('logout');
}
});
});

View File

@@ -3,6 +3,7 @@ import * as template from './lock.component.html';
import { BrowserUtilsService } from '../../../services/abstractions/browserUtils.service';
import { CryptoService } from '../../../services/abstractions/crypto.service';
import { MessagingService } from '../../../services/abstractions/messaging.service';
export class LockController {
i18n: any;
@@ -10,7 +11,7 @@ export class LockController {
constructor(public $state: any, public i18nService: any, private $timeout: any,
private browserUtilsService: BrowserUtilsService, public cryptoService: CryptoService, public toastr: any,
public userService: any, public SweetAlert: any) {
public userService: any, public messagingService: MessagingService, public SweetAlert: any) {
this.i18n = i18nService;
}
@@ -30,7 +31,7 @@ export class LockController {
cancelButtonText: this.i18nService.cancel,
}, (confirmed: boolean) => {
if (confirmed) {
chrome.runtime.sendMessage({ command: 'logout' });
this.messagingService.send('logout');
}
});
}
@@ -48,7 +49,7 @@ export class LockController {
if (storedKeyHash != null && keyHash != null && storedKeyHash === keyHash) {
await this.cryptoService.setKey(key);
chrome.runtime.sendMessage({ command: 'unlocked' });
this.messagingService.send('unlocked');
this.$state.go('tabs.current');
} else {
this.toastr.error(this.i18nService.invalidMasterPassword, this.i18nService.errorsOccurred);

View File

@@ -3,11 +3,13 @@ import { TokenRequest } from '../../../models/request/tokenRequest';
import { BrowserUtilsService } from '../../../services/abstractions/browserUtils.service';
import { CryptoService } from '../../../services/abstractions/crypto.service';
import { MessagingService } from '../../../services/abstractions/messaging.service';
class AuthService {
constructor(public cryptoService: CryptoService, public apiService: any, public userService: any,
public tokenService: any, public $rootScope: any, public appIdService: any,
public browserUtilsService: BrowserUtilsService, public constantsService: any) {
public browserUtilsService: BrowserUtilsService, public constantsService: any,
public messagingService: MessagingService) {
}
async logIn(email: string, masterPassword: string, twoFactorProvider?: number,
@@ -57,7 +59,7 @@ class AuthService {
await this.cryptoService.setEncKey(response.key);
await this.cryptoService.setEncPrivateKey(response.privateKey);
chrome.runtime.sendMessage({ command: 'loggedIn' });
this.messagingService.send('loggedIn');
return {
twoFactor: false,
twoFactorProviders: null,

View File

@@ -4,12 +4,17 @@ import * as backgroundServices from './background.service';
import StateService from './state.service';
import { ValidationService } from './validation.service';
import BrowserMessagingService from '../../../services/browserMessaging.service';
const messagingService = new BrowserMessagingService(backgroundServices.browserUtilsService());
export default angular
.module('bit.services', ['toastr'])
.service('stateService', StateService)
.service('validationService', ValidationService)
.service('authService', AuthService)
.factory('messagingService', () => messagingService)
.factory('storageService', backgroundServices.storageService)
.factory('tokenService', backgroundServices.tokenService)
.factory('cryptoService', backgroundServices.cryptoService)

View File

@@ -1,5 +1,6 @@
import * as angular from 'angular';
import { BrowserUtilsService } from '../../../services/abstractions/browserUtils.service';
import { MessagingService } from '../../../services/abstractions/messaging.service';
import { StorageService } from '../../../services/abstractions/storage.service';
import StateService from '../services/state.service';
import * as template from './options.component.html';
@@ -15,7 +16,8 @@ export class OptionsController {
constructor(private i18nService: any, private $analytics: any, private constantsService: any,
private browserUtilsService: BrowserUtilsService, private totpService: any, private stateService: StateService,
private storageService: StorageService, private $timeout: ng.ITimeoutService) {
private storageService: StorageService, public messagingService: MessagingService,
private $timeout: ng.ITimeoutService) {
this.i18n = i18nService;
$timeout(() => {
@@ -64,9 +66,7 @@ export class OptionsController {
updateDisableContextMenuItem() {
this.storageService.save(this.constantsService.disableContextMenuItemKey,
this.disableContextMenuItem).then(() => {
chrome.runtime.sendMessage({
command: 'bgUpdateContextMenu',
});
this.messagingService.send('bgUpdateContextMenu');
});
this.callAnalytics('Context Menu Item', !this.disableContextMenuItem);
}

View File

@@ -2,6 +2,7 @@ import * as angular from 'angular';
import { BrowserType } from '../../../enums/browserType.enum';
import { BrowserUtilsService } from '../../../services/abstractions/browserUtils.service';
import { CryptoService } from '../../../services/abstractions/crypto.service';
import { MessagingService } from '../../../services/abstractions/messaging.service';
import { StorageService } from '../../../services/abstractions/storage.service';
import ConstantsService from '../../../services/constants.service';
@@ -30,7 +31,7 @@ export class SettingsController {
constructor(private $state: any, private SweetAlert: any, private browserUtilsService: BrowserUtilsService,
private $analytics: any, private i18nService: any, private constantsService: ConstantsService,
private cryptoService: CryptoService, private lockService: any, private storageService: StorageService,
private $timeout: ng.ITimeoutService) {
public messagingService: MessagingService, private $timeout: ng.ITimeoutService) {
this.i18n = i18nService;
$timeout(() => {
@@ -68,7 +69,7 @@ export class SettingsController {
}, (confirmed: boolean) => {
if (confirmed) {
this.cryptoService.toggleKey();
chrome.runtime.sendMessage({ command: 'logout' });
this.messagingService.send('logout');
}
});
}
@@ -93,7 +94,7 @@ export class SettingsController {
cancelButtonText: this.i18nService.cancel,
}, (confirmed: boolean) => {
if (confirmed) {
chrome.runtime.sendMessage({ command: 'logout' });
this.messagingService.send('logout');
}
});
}