Move code that defines ipcRenderer methods into another file.

This commit is contained in:
Thiago de Arruda 2016-08-20 12:26:32 -03:00
Родитель 1713200084
Коммит 0f7652dc85
3 изменённых файлов: 31 добавлений и 28 удалений

Просмотреть файл

@ -61,6 +61,7 @@
'lib/renderer/api/desktop-capturer.js',
'lib/renderer/api/exports/electron.js',
'lib/renderer/api/ipc-renderer.js',
'lib/renderer/api/ipc-renderer-setup.js',
'lib/renderer/api/remote.js',
'lib/renderer/api/screen.js',
'lib/renderer/api/web-frame.js',

Просмотреть файл

@ -0,0 +1,29 @@
module.exports = function (ipcRenderer, binding) {
ipcRenderer.send = function (...args) {
return binding.send('ipc-message', args)
}
ipcRenderer.sendSync = function (...args) {
return JSON.parse(binding.sendSync('ipc-message-sync', args))
}
ipcRenderer.sendToHost = function (...args) {
return binding.send('ipc-message-host', args)
}
ipcRenderer.sendTo = function (webContentsId, channel, ...args) {
if (typeof webContentsId !== 'number') {
throw new TypeError('First argument has to be webContentsId')
}
ipcRenderer.send('ELECTRON_BROWSER_SEND_TO', false, webContentsId, channel, ...args)
}
ipcRenderer.sendToAll = function (webContentsId, channel, ...args) {
if (typeof webContentsId !== 'number') {
throw new TypeError('First argument has to be webContentsId')
}
ipcRenderer.send('ELECTRON_BROWSER_SEND_TO', true, webContentsId, channel, ...args)
}
}

Просмотреть файл

@ -5,33 +5,6 @@ const v8Util = process.atomBinding('v8_util')
// Created by init.js.
const ipcRenderer = v8Util.getHiddenValue(global, 'ipc')
ipcRenderer.send = function (...args) {
return binding.send('ipc-message', args)
}
ipcRenderer.sendSync = function (...args) {
return JSON.parse(binding.sendSync('ipc-message-sync', args))
}
ipcRenderer.sendToHost = function (...args) {
return binding.send('ipc-message-host', args)
}
ipcRenderer.sendTo = function (webContentsId, channel, ...args) {
if (typeof webContentsId !== 'number') {
throw new TypeError('First argument has to be webContentsId')
}
ipcRenderer.send('ELECTRON_BROWSER_SEND_TO', false, webContentsId, channel, ...args)
}
ipcRenderer.sendToAll = function (webContentsId, channel, ...args) {
if (typeof webContentsId !== 'number') {
throw new TypeError('First argument has to be webContentsId')
}
ipcRenderer.send('ELECTRON_BROWSER_SEND_TO', true, webContentsId, channel, ...args)
}
require('./ipc-renderer-setup')(ipcRenderer, binding)
module.exports = ipcRenderer