I am kind of new to Electron/Js and I'm having trouble creating this piece of code. I have an ordinary menu [ Home, Topic1, Topic2, Calculator...etc. ] and I'm trying to open a new window when the user clicks on "Calculator" in the menu. I have created the window and used the property "show: false;" but I can't figure out how to "wire it up" to make the link to send a signal and execute "altWindow.show()" for example. I have been looking quite a bit in the Electron docs and I just can't figure it out. I did try with event listeners but something doesn't work quite right.
答案 0 :(得分:1)
要打开一个新窗口,您需要让主要流程将显示更改为您创建的窗口的true
。
在渲染器进程(主窗口)中,使用ipcRenderer向主进程发送消息。
在主要流程中,使用ipcMain来监听事件,并在附加的处理程序中更新第二个窗口以显示true
。
<强>渲染强>
buttonClicked(e){
e.preventDefault()
ipcRenderer.send('open-calc')
}
主要强>
ipcMain.on('open-calc', function(){
calcWindow.show() // Assuming that your calculator window is the variable calcWindow
})