ipcMain
线程:主线程
It is also possible to send messages from the main process to the renderer process, see [webContents.send][web-contents-send] for more information.
- 发送消息时,事件名称为。
- 回复同步信息时,需要设置
event.returnValue
。
//在渲染器进程 (网页) 中。
const { ipcRenderer } = require('electron')
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')) // prints "pong"
ipcRenderer.on('asynchronous-reply', (event, arg) => {
console.log(arg) // prints "pong"
})
channel
String
channel
String-
event
IpcMainEvent- any[]添加一次性的
listener
。当且仅当下一个消息发送到channel
时listener
才会被调用,随后 <0>listener</0> 会被移除。
channel
Stringlistener
Function从监听器数组中移除监听channel
的指定listener
。
channel
String删除所有监听者,或特指的 channel 的所有监听者.
The documentation for the event
object passed to the callback
can be found in the structure docs.