diff --git a/src/electron/services/electronRendererMessaging.service.ts b/src/electron/services/electronRendererMessaging.service.ts new file mode 100644 index 0000000000..9dedd360a7 --- /dev/null +++ b/src/electron/services/electronRendererMessaging.service.ts @@ -0,0 +1,21 @@ +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.send(message.command, message); + } + }); + } + + send(subscriber: string, arg: any = {}) { + const message = Object.assign({}, { command: subscriber }, arg); + ipcRenderer.send('messagingService', message); + this.broadcasterService.send(message); + } +}