Implement full IPC API on render process #73
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For the app I'm working on, I'd like to be able to communicate arbitrary messages between the main and render processes. It requires a tray, etc., so I'm using a fork of the
app/
directory inprivate/
as recommended in the readme. I think the best way for the main and render processes to communicate is via messages, in the direction suggested in #58, rather than to expose functions directly.IPC is present in Electron for this purpose, but the full API is currently limited on the render process by
meson:electron
.Electron.onEvent()
allows the render process to receive an IPC message from main, but it does not pass through the event object or any additional parameters you may want to send. Also, there is no way to signal up to the main process.The code in this PR proposes changing
Electron.onEvent()
to provide the full IPC API as documented here and addingElectron.sendIpcEvent()
for communication from render process to main. I'm not attached to the exact method names. In fact, it might make sense to name them closer to the Electron API:Electron.ipcRendererOn()
andElectron.ipcRendererSend()
or similar so that new users can relate it to the Electron docs more readily.These changes make it possible to safely provide any functionality needed. It might make sense to add a method/RPC type of abstraction on top of this where you could provide something like
Electron.call('setTrayIcon', 'alert')
orElectron.call('promptUser', choices)
which could return a promise or otherwise help with async responses. This would feel natural to Meteor devs and wouldn't add much code tomeson:electron
.