electron/lib/renderer/api/ipc.js

28 lines
770 B
JavaScript
Raw Normal View History

2016-03-25 19:57:17 +00:00
const ipcRenderer = require('electron').ipcRenderer
const deprecate = require('electron').deprecate
const EventEmitter = require('events').EventEmitter
2016-01-12 02:40:23 +00:00
2016-01-14 18:35:29 +00:00
// This module is deprecated, we mirror everything from ipcRenderer.
2016-03-25 19:57:17 +00:00
deprecate.warn('ipc module', 'require("electron").ipcRenderer')
2016-01-12 02:40:23 +00:00
2016-01-14 18:35:29 +00:00
// Routes events of ipcRenderer.
2016-03-25 19:57:17 +00:00
var ipc = new EventEmitter
2016-01-12 02:40:23 +00:00
2016-03-25 19:57:17 +00:00
ipcRenderer.emit = function (channel, event, ...args) {
ipc.emit.apply(ipc, [channel].concat(args))
return EventEmitter.prototype.emit.apply(ipcRenderer, arguments)
}
2016-01-12 02:40:23 +00:00
2016-01-14 18:35:29 +00:00
// Deprecated.
2016-01-14 22:20:06 +00:00
for (var method in ipcRenderer) {
2016-01-12 02:40:23 +00:00
if (method.startsWith('send')) {
2016-03-25 19:57:17 +00:00
ipc[method] = ipcRenderer[method]
2016-01-12 02:40:23 +00:00
}
}
2016-03-25 19:57:17 +00:00
deprecate.rename(ipc, 'sendChannel', 'send')
2016-01-12 02:40:23 +00:00
2016-03-25 19:57:17 +00:00
deprecate.rename(ipc, 'sendChannelSync', 'sendSync')
2016-01-12 02:40:23 +00:00
2016-03-25 19:57:17 +00:00
module.exports = ipc