Use ES6 template strings, fix docs and remove _ERROR_ IPC event
This commit is contained in:
parent
857e1da6a3
commit
9f18a6e65c
4 changed files with 10 additions and 12 deletions
|
@ -621,7 +621,7 @@ Injects CSS into the current web page.
|
|||
* `result` Any
|
||||
|
||||
Returns `Promise` - A promise that resolves with the result of the executed code
|
||||
or is rejected if the result of the code is a rejected promise
|
||||
or is rejected if the result of the code is a rejected promise.
|
||||
|
||||
Evaluates `code` in page.
|
||||
|
||||
|
|
|
@ -112,12 +112,10 @@ const webFrameMethodsWithResult = [
|
|||
const asyncWebFrameMethods = function (requestId, method, callback, ...args) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.send('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', requestId, method, args)
|
||||
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, result) {
|
||||
if (callback) callback(result)
|
||||
resolve(result)
|
||||
})
|
||||
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_ERROR_${requestId}`, (event, error) => {
|
||||
reject(error)
|
||||
ipcMain.once(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, function (event, error, result) {
|
||||
if (callback && !error) callback(result)
|
||||
if (error) return reject(error)
|
||||
return resolve(result)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -41,10 +41,10 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (ev
|
|||
const responseCallback = function (result) {
|
||||
Promise.resolve(result)
|
||||
.then((resolvedResult) => {
|
||||
event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, resolvedResult)
|
||||
event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, null, resolvedResult)
|
||||
})
|
||||
.catch((resolvedError) => {
|
||||
event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_ERROR_${requestId}`, resolvedError)
|
||||
event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, resolvedError)
|
||||
})
|
||||
}
|
||||
args.push(responseCallback)
|
||||
|
|
|
@ -1463,9 +1463,9 @@ describe('browser-window module', function () {
|
|||
describe('window.webContents.executeJavaScript', function () {
|
||||
var expected = 'hello, world!'
|
||||
var expectedErrorMsg = 'woops!'
|
||||
var code = '(() => "' + expected + '")()'
|
||||
var asyncCode = '(() => new Promise(r => setTimeout(() => r("' + expected + '"), 500)))()'
|
||||
var badAsyncCode = '(() => new Promise((r, e) => setTimeout(() => e("' + expectedErrorMsg + '"), 500)))()'
|
||||
var code = `(() => "${expected}")()`
|
||||
var asyncCode = `(() => new Promise(r => setTimeout(() => r("${expected}"), 500)))()`
|
||||
var badAsyncCode = `(() => new Promise((r, e) => setTimeout(() => e("${expectedErrorMsg}"), 500)))()`
|
||||
|
||||
it('doesnt throw when no calback is provided', function () {
|
||||
const result = ipcRenderer.sendSync('executeJavaScript', code, false)
|
||||
|
|
Loading…
Reference in a new issue