From fb5ab2771b0c19d22aa6f1ac0079043efe3e6960 Mon Sep 17 00:00:00 2001 From: Robert Dickert Date: Wed, 30 Mar 2016 11:01:30 -0600 Subject: [PATCH 1/2] implement full ipc api on both main & render processes --- app/preload.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/preload.js b/app/preload.js index 5d331be..367e139 100644 --- a/app/preload.js +++ b/app/preload.js @@ -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 */) { + ipc.send.apply(null, arguments); + }, }; From d83c1ba40576bc16c0c2c798913670a2724379ec Mon Sep 17 00:00:00 2001 From: Robert Dickert Date: Wed, 11 May 2016 15:43:19 -0600 Subject: [PATCH 2/2] change `sendIpcEvent()` to `send` --- app/preload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/preload.js b/app/preload.js index 367e139..826cf39 100644 --- a/app/preload.js +++ b/app/preload.js @@ -89,7 +89,7 @@ ElectronImplementation = { * @param {String} event - The name of an event. * @param {...*} arg - additional arguments to pass to event handler. */ - sendIpcEvent: function(/* event , ...args */) { + send: function(/* event , ...args */) { ipc.send.apply(null, arguments); }, };