Last active
February 2, 2017 08:35
-
-
Save hackjutsu/dc8862fd8dd78ebd7e52b0e29e2b83fb to your computer and use it in GitHub Desktop.
[Sending IPC events from main to renderer in Electron] (http://stackoverflow.com/a/36809014/3697757) #tags: electron,lepton
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
| // To send events to particular window you can use webContents.send(EVENT_NAME, ARGS) (see docs). webContents is a property of a window instance: | |
| // main process | |
| storeWindow.webContents.send('store-data', store); | |
| // To listen for this event being sent, you need a listener in a window process (renderer): | |
| // renderer process | |
| // ipcRenderer is provided by electron package. You can import it like this: var ipcRenderer = require('electron').ipcRenderer; or es6 import { ipcRenderer } from 'electron'; | |
| import { ipcRenderer } from 'electron'; | |
| ipcRenderer.on('store-data', function (store) { | |
| console.log(store); | |
| }); | |
| // unregister the listener | |
| ipcRenderer.removeAllListeners('store-data'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment