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