damien damien - 1 year ago 385
Javascript Question

How to pass parameters from main process to render processes in Electron

I have an Electron app that can open different windows.

On app launch the app open a set of window(s) (that load the same HTML and JS files) but with params to change each window displayed infos.

Example :

app.on('ready', async () => {
// open window for stuff 1
win1 = new BrowserWindow({
width: 1024,
height: 728

// open window for stuff 2
win2 = new BrowserWindow({
width: 1024,
height: 728

Obviously passing params in file:// path doesn't work.
I can't find a clear solution in Electron documentation or elsewhere on Internet to condition my rendered window to a param.

I can probably use IPC communication after window ready but it seems a little bit too complicated until I just want pass a variable to my child view.

P.S. : to be totally honest my application is built with React/Redux and the param I want to pass to view is the redux store key to listen for this view.

Answer Source

According atom source code the query string method is a reliable way to do that very simply, especially when we only need to pass a unique string param:

// main process

// rendered process


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download