Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  38] [ 4]  / answers: 1 / hits: 43040  / 8 Years ago, tue, july 12, 2016, 12:00:00

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
});
win1.loadURL(`file://${__dirname}/app/app.html?id=1`);

// open window for stuff 2
win2 = new BrowserWindow({
width: 1024,
height: 728
});
win2.loadURL(`file://${__dirname}/app/app.html?id=2`);


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.


More From » electron

 Answers
8

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
win1.loadURL(`file://${__dirname}/app/app.html?id=${id}`);

// rendered process
console.log(global.location.search);


https://github.com/electron/electron/issues/6504


[#61403] Monday, July 11, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleyi

Total Points: 121
Total Questions: 100
Total Answers: 109

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
;