Electron: renderer access to main process?

你。 提交于 2020-01-04 05:32:56

问题


The main process opens a connection to a service, to which a renderer requires access.

Is this possible?

I've tried declaring global.thing and exports.thing, and having the renderer require('electron').remote.thing — where thing is a function or scalar — but no luck.


回答1:


You can do it in more ways:

1) Communicate between process with ipc and ask data with ipcRenderer.sendSync function, that asks to main process and wait for a return value. https://github.com/electron/electron/blob/master/docs/api/ipc-renderer.md

2) use exports in the right way, so:

in the main process:

exports.functionName = functionName;

in the renderer:

var functionName = remote.require('./main').functionName;


来源:https://stackoverflow.com/questions/41166869/electron-renderer-access-to-main-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!