1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 19:23:52 +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

@@ -0,0 +1,3 @@
export interface MessagingService {
send(subscriber: string, arg?: any): void;
}

View File

@@ -0,0 +1,13 @@
import { BrowserUtilsService } from './abstractions/browserUtils.service';
import { MessagingService as MessagingServiceInterface } from './abstractions/messaging.service';
export default class BrowserMessagingService implements MessagingServiceInterface {
constructor(private browserUtilsService: BrowserUtilsService) {
}
send(subscriber: string, arg: any = {}) {
// if safari, else
const message = Object.assign({}, { command: subscriber }, arg);
chrome.runtime.sendMessage(message);
}
}

View File

@@ -17,6 +17,7 @@ import FolderService from './folder.service';
import SettingsService from './settings.service';
import UserService from './user.service';
import { MessagingService } from './abstractions/messaging.service';
import { StorageService } from './abstractions/storage.service';
const Keys = {
@@ -30,7 +31,7 @@ export default class SyncService {
private settingsService: SettingsService, private folderService: FolderService,
private cipherService: CipherService, private cryptoService: CryptoService,
private collectionService: CollectionService, private storageService: StorageService,
private logoutCallback: Function) {
private messagingService: MessagingService, private logoutCallback: Function) {
}
async getLastSync() {
@@ -50,13 +51,12 @@ export default class SyncService {
syncStarted() {
this.syncInProgress = true;
chrome.runtime.sendMessage({ command: 'syncStarted' });
this.messagingService.send('syncStarted');
}
syncCompleted(successfully: boolean) {
this.syncInProgress = false;
// tslint:disable-next-line
chrome.runtime.sendMessage({ command: 'syncCompleted', successfully: successfully });
this.messagingService.send('syncCompleted', { successfully: successfully });
}
async fullSync(forceSync: boolean) {