电子:渲染器访问主进程?
主进程打开一个到渲染器需要访问的服务的连接。
这可能吗?
我试过声明global.thing
和global.thing
,并让渲染器require('electron').remote.thing
– 其中的东西是函数或标量 – 但没有运气。
你可以用更多的方法做到这一点:
1)在进程与ipc之间进行通信,并用ipcRenderer.sendSync函数询问数据,请求主进程并等待返回值。 https://github.com/electron/electron/blob/master/docs/api/ipc-renderer.md
2)以正确的方式使用出口,所以:
在主要过程中:
exports.functionName = functionName;
在渲染器中:
var functionName = remote.require('./main').functionName;