Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement full IPC API on render process #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions app/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,29 @@ ElectronImplementation = {
* Invokes _callback_ when the specified IPC event is fired.
*
* @param {String} event - The name of an event.
* @param {Function} callback - A function to invoke when `event` is triggered. Takes no arguments
* and returns no value.
* @param {Function} callback - A function to invoke when `event` is triggered. Called with
* the signature (event, ...args) - see http://electron.atom.io/docs/v0.37.2/api/ipc-renderer/#sending-messages
*/
onEvent: function(event, callback) {
var listeners = this._eventListeners[event];
if (!listeners) {
listeners = this._eventListeners[event] = [];
ipc.on(event, function() {
_.invoke(listeners, 'call');
ipc.on(event, function(/* event, ...args */) {
_.invoke(listeners, 'apply', null, arguments);
});
}
listeners.push(callback);
},

_eventListeners: {}
_eventListeners: {},

/**
* Send an event to the main Electron process.
*
* @param {String} event - The name of an event.
* @param {...*} arg - additional arguments to pass to event handler.
*/
sendIpcEvent: function(/* event , ...args */) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind naming this method send? I think that's actually most consistent with the IPC APIs—I should have named the other one just on. I think I just named it onEvent because I was using it more for listening to events than full two-way message passing at that time.

ipc.send.apply(null, arguments);
},
};