Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pinalbhatt
Forked from sommereder/index.html
Created February 26, 2017 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinalbhatt/4674f2948e674c62e2ea27ba89aa0b61 to your computer and use it in GitHub Desktop.
Save pinalbhatt/4674f2948e674c62e2ea27ba89aa0b61 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 //////////////////////////////////////////////////////////////////////////////////////////////////
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment