Two Windows in Electron / React Redux

272 views Asked by At

What I Want

Initially, mainWindow is visible and callWindow is closed.

If I type in searchInput and click on button in mainWindow, then I want:

  • callWindow.show()

  • callWindow runs this.props.dispatch(push("/calls", {searchInput}))

Where I'm Stuck

in main.js...

mainWindow = new BrowserWindow(options)
callWindow = new BrowserWindow(options)
ipcMain.on("buttonClick", (event, arg) => {
    callWindow.show();
    // STUCK! How to make callWindow react code run: this.props.dispatch(push("/calls", {searchInput}))
});

In react code..

onButtonClick() {
    ipcRender.send("buttonClick", input)
}
1

There are 1 answers

2
tpikachu On
ipcMain.on("buttonClick", (event, arg) => {
    callWindow.show();
    callWindow.webContents.send('dispatch', searchInput);
    // STUCK! How to make callWindow react code run: dispatch(push("/calls", {searchInput}))
});

At callWindow renderer (callWindodw React code)

componentDidMount() {
   ...
   ipcRenderer.on('dispatch', (event, searchInput) => {
      this.props.dispatch(push("/calls", {searchInput}))
   })
}