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
30
lib/renderer/ipc-renderer-internal-utils.js
Normal file
30
lib/renderer/ipc-renderer-internal-utils.js
Normal 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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue