refactor: use helpers when using the remote module in sandboxed renderers (#15960)

This commit is contained in:
Milan Burda 2018-12-05 19:07:32 +01:00 committed by Shelley Vohr
commit ab2a061b59
11 changed files with 46 additions and 28 deletions

View file

@ -2,9 +2,24 @@
const { remote } = require('electron')
exports.getRemoteForUsage = function (usage) {
exports.getRemote = function (name) {
if (!remote) {
throw new Error(`${name} requires remote, which is not enabled`)
}
return remote[name]
}
exports.getRemoteFor = function (usage) {
if (!remote) {
throw new Error(`${usage} requires remote, which is not enabled`)
}
return remote
}
exports.nativeRequire = function (name) {
if (process.sandboxed) {
return exports.getRemoteFor(name).require(name)
} else {
return require(name)
}
}