refactor: implement inspector APIs without the remote module (#16607)

This commit is contained in:
Milan Burda 2019-02-01 19:56:46 +01:00 committed by Alexey Kuzmin
parent 392458b252
commit 7dc565fc2e
7 changed files with 205 additions and 96 deletions

View 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
})
})
}