bitwarden-estensione-browser/src/electron/services/electronRendererMessaging.s...

28 lines
954 B
TypeScript
Raw Normal View History

import { ipcRenderer } from 'electron';
import { MessagingService } from '../../abstractions/messaging.service';
import { BroadcasterService } from '../../angular/services/broadcaster.service';
export class ElectronRendererMessagingService implements MessagingService {
constructor(private broadcasterService: BroadcasterService) {
ipcRenderer.on('messagingService', async (event: any, message: any) => {
if (message.command) {
this.sendMessage(message.command, message, false);
}
});
}
send(subscriber: string, arg: any = {}) {
this.sendMessage(subscriber, arg, true);
}
private sendMessage(subscriber: string, arg: any = {}, toMain: boolean) {
const message = Object.assign({}, { command: subscriber }, arg);
this.broadcasterService.send(message);
if (toMain) {
ipcRenderer.send('messagingService', message);
}
}
}