简体   繁体   中英

Electron: renderer access to main process?

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM