【问题标题】:Two Windows in Electron / React ReduxElectron / React Redux 中的两个窗口
【发布时间】:2020-08-25 10:15:19
【问题描述】:

我想要什么

最初,mainWindow 是可见的,而 callWindow 是关闭的。

如果我输入 searchInput 并单击 mainWindow 中的按钮,那么我想要:

  • callWindow.show()

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

我被困在哪里

在 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}))
});

在反应代码中..

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

【问题讨论】:

    标签: reactjs redux react-redux electron windowstate


    【解决方案1】:
    ipcMain.on("buttonClick", (event, arg) => {
        callWindow.show();
        callWindow.webContents.send('dispatch', searchInput);
        // STUCK! How to make callWindow react code run: dispatch(push("/calls", {searchInput}))
    });
    

    在 callWindow 渲染器(callWindodw React 代码)

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

    【讨论】:

    • 这里有完整的代码。我确定您使用的是基于类的组件。所以你应该把这个监听器添加到你的生命周期函数中。
    • 顺便说一句,我喜欢你的名字
    猜你喜欢
    • 2021-02-12
    • 2019-07-28
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 2018-06-04
    • 1970-01-01
    • 2019-01-01
    相关资源
    最近更新 更多