ipc-renderer.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict'
  2. const { ipc } = process.electronBinding('ipc')
  3. const v8Util = process.electronBinding('v8_util')
  4. // Created by init.js.
  5. const ipcRenderer = v8Util.getHiddenValue(global, 'ipc')
  6. const internal = false
  7. ipcRenderer.send = function (channel, ...args) {
  8. return ipc.send(internal, channel, args)
  9. }
  10. ipcRenderer.sendSync = function (channel, ...args) {
  11. return ipc.sendSync(internal, channel, args)[0]
  12. }
  13. ipcRenderer.sendToHost = function (channel, ...args) {
  14. return ipc.sendToHost(channel, args)
  15. }
  16. ipcRenderer.sendTo = function (webContentsId, channel, ...args) {
  17. return ipc.sendTo(internal, false, webContentsId, channel, args)
  18. }
  19. ipcRenderer.sendToAll = function (webContentsId, channel, ...args) {
  20. return ipc.sendTo(internal, true, webContentsId, channel, args)
  21. }
  22. ipcRenderer.invoke = function (channel, ...args) {
  23. return ipc.invoke(channel, args).then(({ error, result }) => {
  24. if (error) { throw new Error(`Error invoking remote method '${channel}': ${error}`) }
  25. return result
  26. })
  27. }
  28. module.exports = ipcRenderer