Move code that defines ipcRenderer methods into another file.
This commit is contained in:
parent
1713200084
commit
0f7652dc85
3 changed files with 31 additions and 28 deletions
|
@ -61,6 +61,7 @@
|
||||||
'lib/renderer/api/desktop-capturer.js',
|
'lib/renderer/api/desktop-capturer.js',
|
||||||
'lib/renderer/api/exports/electron.js',
|
'lib/renderer/api/exports/electron.js',
|
||||||
'lib/renderer/api/ipc-renderer.js',
|
'lib/renderer/api/ipc-renderer.js',
|
||||||
|
'lib/renderer/api/ipc-renderer-setup.js',
|
||||||
'lib/renderer/api/remote.js',
|
'lib/renderer/api/remote.js',
|
||||||
'lib/renderer/api/screen.js',
|
'lib/renderer/api/screen.js',
|
||||||
'lib/renderer/api/web-frame.js',
|
'lib/renderer/api/web-frame.js',
|
||||||
|
|
29
lib/renderer/api/ipc-renderer-setup.js
Normal file
29
lib/renderer/api/ipc-renderer-setup.js
Normal file
|
@ -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.
|
// Created by init.js.
|
||||||
const ipcRenderer = v8Util.getHiddenValue(global, 'ipc')
|
const ipcRenderer = v8Util.getHiddenValue(global, 'ipc')
|
||||||
|
require('./ipc-renderer-setup')(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)
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = ipcRenderer
|
module.exports = ipcRenderer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue