Allow web frame methods to return async promises

This commit is contained in:
Samuel Attard 2016-10-09 11:51:46 +11:00 committed by Kevin Sawicki
parent cf0cd5b50b
commit 124fbdbd74

View file

@ -39,7 +39,13 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_SYNC_WEB_FRAME_METHOD', (eve
electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (event, requestId, method, args) => {
const responseCallback = function (result) {
event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, result)
Promise.resolve(result)
.then((resolvedResult) => {
event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, resolvedResult)
})
.catch((resolvedError) => {
console.error(`An async web frame method (${method}) returned a promise that threw an error: `, resolvedError)
})
}
args.push(responseCallback)
electron.webFrame[method].apply(electron.webFrame, args)