feat: add ipcRenderer.invoke() (#18449)
This commit is contained in:
parent
b180fb376c
commit
c436997840
17 changed files with 389 additions and 20 deletions
|
@ -326,6 +326,19 @@ WebContents.prototype._init = function () {
|
|||
}
|
||||
})
|
||||
|
||||
this.on('-ipc-invoke', function (event, channel, args) {
|
||||
event._reply = (result) => event.sendReply({ result })
|
||||
event._throw = (error) => {
|
||||
console.error(`Error occurred in handler for '${channel}':`, error)
|
||||
event.sendReply({ error: error.toString() })
|
||||
}
|
||||
if (ipcMain._invokeHandlers.has(channel)) {
|
||||
ipcMain._invokeHandlers.get(channel)(event, ...args)
|
||||
} else {
|
||||
event._throw(`No handler registered for '${channel}'`)
|
||||
}
|
||||
})
|
||||
|
||||
this.on('-ipc-message-sync', function (event, internal, channel, args) {
|
||||
addReturnValueToEvent(event)
|
||||
if (internal) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue