asarfuckery/electronasar/stable/renderer/web-frame-init.js

25 lines
823 B
JavaScript
Raw Normal View History

2019-01-17 18:22:05 +00:00
'use strict'
const { webFrame } = require('electron')
const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
const errorUtils = require('@electron/internal/common/error-utils')
module.exports = () => {
// Call webFrame method
ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', (event, method, args) => {
webFrame[method](...args)
})
ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (event, requestId, method, args) => {
new Promise(resolve =>
webFrame[method](...args, resolve)
).then(result => {
return [null, result]
}, error => {
return [errorUtils.serialize(error)]
}).then(responseArgs => {
event.sender.send(`ELECTRON_INTERNAL_BROWSER_ASYNC_WEB_FRAME_RESPONSE_${requestId}`, ...responseArgs)
})
})
}