2019-02-01 18:56:46 +00:00
|
|
|
'use strict'
|
|
|
|
|
2019-02-04 22:49:53 +00:00
|
|
|
const { ipcMainInternal } = require('@electron/internal/browser/ipc-main-internal')
|
2019-02-01 18:56:46 +00:00
|
|
|
const errorUtils = require('@electron/internal/common/error-utils')
|
|
|
|
|
|
|
|
const callHandler = async function (handler, event, args, reply) {
|
|
|
|
try {
|
|
|
|
const result = await handler(event, ...args)
|
|
|
|
reply([null, result])
|
|
|
|
} catch (error) {
|
|
|
|
reply([errorUtils.serialize(error)])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.handle = function (channel, handler) {
|
2019-02-04 22:49:53 +00:00
|
|
|
ipcMainInternal.on(channel, (event, requestId, ...args) => {
|
2019-02-01 18:56:46 +00:00
|
|
|
callHandler(handler, event, args, responseArgs => {
|
|
|
|
event._replyInternal(`${channel}_RESPONSE_${requestId}`, ...responseArgs)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.handleSync = function (channel, handler) {
|
2019-02-04 22:49:53 +00:00
|
|
|
ipcMainInternal.on(channel, (event, ...args) => {
|
2019-02-01 18:56:46 +00:00
|
|
|
callHandler(handler, event, args, responseArgs => {
|
|
|
|
event.returnValue = responseArgs
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|