电子:渲染器访问主进程? [英] Electron: renderer access to main process?

查看:55
本文介绍了电子:渲染器访问主进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主进程打开与渲染器要求访问的服务的连接。

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

这可能吗?

我尝试声明 global.thing exports.thing ,并使渲染器 require('electron')。remote.thing —凡事是函数或标量—但没有运气。

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.

推荐答案

您可以通过更多方式做到这一点:

You can do it in more ways:

1)使用 ipc 在进程之间进行通信,并使用 ipcRenderer.sendSync 询问数据/ strong>函数,该函数询问主进程并等待返回值。
https://github.com/electron /electron/blob/master/docs/api/ipc-renderer.md

2)以正确的方式使用导出,因此:

2) use exports in the right way, so:

在主要过程中:

exports.functionName = functionName;

在渲染器中:

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

这篇关于电子:渲染器访问主进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆