refactor: implement inspector APIs without the remote module (#16607)
This commit is contained in:
parent
392458b252
commit
7dc565fc2e
7 changed files with 205 additions and 96 deletions
29
lib/browser/ipc-main-internal-utils.js
Normal file
29
lib/browser/ipc-main-internal-utils.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
'use strict'
|
||||
|
||||
const ipcMain = require('@electron/internal/browser/ipc-main-internal')
|
||||
const errorUtils = require('@electron/internal/common/error-utils')
|
||||
|
||||
const callHandler = async function (handler, event, args, reply) {
|
||||
try {
|
||||
const result = await handler(event, ...args)
|
||||
reply([null, result])
|
||||
} catch (error) {
|
||||
reply([errorUtils.serialize(error)])
|
||||
}
|
||||
}
|
||||
|
||||
exports.handle = function (channel, handler) {
|
||||
ipcMain.on(channel, (event, requestId, ...args) => {
|
||||
callHandler(handler, event, args, responseArgs => {
|
||||
event._replyInternal(`${channel}_RESPONSE_${requestId}`, ...responseArgs)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
exports.handleSync = function (channel, handler) {
|
||||
ipcMain.on(channel, (event, ...args) => {
|
||||
callHandler(handler, event, args, responseArgs => {
|
||||
event.returnValue = responseArgs
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue