import { Injectable , NgZone } from '@angular/core' ; const { ipcRenderer } = electron ; @ Injectable ( ) export class IpcRendererService { private _ipcRenderer = ipcRenderer ; private listeners = [ ] ; constructor ( private zone ) { } public on ( channel , callback ) { const ipcListener = ( event , args ) => { this . zone . run ( ( ) => { callback ( event , args ) ; } ) ; } ; this . listeners . push ( { fct : callback , ipcListener : ipcListener } ) ; return this . _ipcRenderer . on ( channel , ipcListener ) ; } public removeListener ( channel , listener ) { let ipcListener = null ; this . listeners . forEach ( ( l ) => { if ( l . fct == listener ) ipcListener = l . ipcListener ; } ) ; return this . _ipcRenderer . removeListener ( channel , ipcListener ) ; } public removeAllListeners ( channel ? ) { return this . _ipcRenderer . removeAllListeners ( channel ) ; } public send ( channel , ... args ) { this . _ipcRenderer . send ( channel , args ) ; } public sendSync ( channel , ... args ) { return this . _ipcRenderer . sendSync ( channel , args ) ; } }