私は、最初のウィンドウで状態の変化を通知する別のウィンドウで状態を更新しようとしていますが、ipcの通信は私にとって期待通りに機能しません。私の最初のウィンドウで電子+反応+ 2つのウィンドウ間の通信はPCをフリーズしますか?
は、私が持っている:
onStatsSelect(event, menuItem, index) {
const selectedStatsCopy = this.state.selectedStats.slice();
const itemIndex = selectedStatsCopy.indexOf(menuItem.props.primaryText);
if (itemIndex > -1) {
delete selectedStatsCopy[itemIndex];
} else {
selectedStatsCopy[index] = menuItem.props.primaryText;
}
// Update state
this.setState({ selectedStats: selectedStatsCopy });
// Notify worker window of change
if (!(this.props.isReport)) {
console.log('in renderer main window');
ipcRenderer.send("updateSelectedStatsMain", event, selectedStatsCopy);
}
}
これはselectedStats状態を更新するためのコールバックです。最後の行に示されているように、この更新プログラムのワーカーウィンドウにも通知します。 if (!(this.props.isReport))
両方のウィンドウが同じコンポーネントを共有しているので、これは重要なチェックです。したがって、これらのウィンドウを区別するためにプロパティーisReport
を使用します。私の主なプロセスで
、私が持っている:
// Selected Stats have changed in main window
ipcMain.on('updateSelectedStatsMain', (event, selectedStatsCopy) => {
console.log('in main');
// Send to worker window
workerWindow.webContents.send('updateSelectedStatsRen', event, selectedStatsCopy);
});
このコードは、新しい状態selectedStatsCopy
と労働者のウィンドウに戻って通信します。私comoponentDidMount
で
、私が持っている:
componentDidMount() {
// Register listening to message in case this is the worker window
if (this.props.isReport) {
console.log('in renderer worker window');
ipcRenderer.on("updateSelectedStatsRen", (event, selectedStatsCopy) => {
console.log('in renderer worker window event');
this.setState({ selectedStats: selectedStatsCopy });
});
}
}
これが動作するようになったが、電子は、メインウィンドウには、しばらくの間、ハングし、PCがフリーズするまで、それはリソースを使用し続けて作るラインipcRenderer.send("updateSelectedStatsMain", event, selectedStatsCopy);
でハングアップしています。
ここで問題は何ですか?
おそらくどこかでループがあります。たとえば、レンダリングメソッドでsetStateを試行すると、再描画ループが発生します。そのようなことを見てください。 –
私は考え出したと思う。メソッドに来るパラメータは、私が期待しているものではありません。 – Kafo
いいえ、そうではありませんでした。まだこれを解決することはできません:( – Kafo