Skip to content

Instantly share code, notes, and snippets.

@sommereder
Created May 11, 2016 07:47
Show Gist options
  • Save sommereder/638e63b5695702b793845c3a29328dac to your computer and use it in GitHub Desktop.
Save sommereder/638e63b5695702b793845c3a29328dac to your computer and use it in GitHub Desktop.
IPC Renderer Service for Electron/Angular2
<script>
const electron = require('electron');
// below is just plain angular stuff
System
.config({
packages: {
angular: {
format: 'register',
defaultExtension: 'js'
}
}
})
;
System
.import('./angular/main.js')
.then(null, console.error.bind(console))
;
</script>
import {Injectable} from 'angular2/core';
declare var electron:any;
@Injectable()
export class IpcRendererService {
ipcRenderer = electron.ipcRenderer;
// CONSTRUCTOR ////////////////////////////////////////////////////////////////////////////////////////////////////
constructor() {}
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////////////////////
on(message:string, callback) {
return this.ipcRenderer.on(message, callback);
}
send(message:string, ...args) {
this.ipcRenderer.send(message, args);
}
sendSync(message:string, ...args) {
return this.ipcRenderer.sendSync(message, arguments);
}
// EVENT HANDLER //////////////////////////////////////////////////////////////////////////////////////////////////
}
@artfanvikram
Copy link

in the sendSync method arguments is passed for ipcRenderer.sendSync() , is that a typo or intentional. Should it be args?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment