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,30 @@
'use strict'
const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
const errorUtils = require('@electron/internal/common/error-utils')
let nextId = 0
exports.invoke = function (command, ...args) {
return new Promise((resolve, reject) => {
const requestId = ++nextId
ipcRenderer.once(`${command}_RESPONSE_${requestId}`, (event, error, result) => {
if (error) {
reject(errorUtils.deserialize(error))
} else {
resolve(result)
}
})
ipcRenderer.send(command, requestId, ...args)
})
}
exports.invokeSync = function (command, ...args) {
const [ error, result ] = ipcRenderer.sendSync(command, ...args)
if (error) {
throw errorUtils.deserialize(error)
} else {
return result
}
}