rsnext/examples/with-electron/main/preload.js
Henrik Wenz 2cfcab8a74
Update with-electron example (#23873)
This PR updates `example/with-electron`:

- Updates electron to version [12 (latest stable)](https://www.electronjs.org/releases/stable#12.0.2)
- Introduces the new `contextBridge` to increase security ([docs](https://www.electronjs.org/docs/api/context-bridge))



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [x] Make sure the linting passes
2021-04-11 15:38:15 +00:00

9 lines
304 B
JavaScript

const { ipcRenderer, contextBridge } = require('electron')
contextBridge.exposeInMainWorld('electron', {
message: {
send: (payload) => ipcRenderer.send('message', payload),
on: (handler) => ipcRenderer.on('message', handler),
off: (handler) => ipcRenderer.off('message', handler),
},
})