-
-
Save pinalbhatt/4674f2948e674c62e2ea27ba89aa0b61 to your computer and use it in GitHub Desktop.
IPC Renderer Service for Electron/Angular2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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