Pass app path as command line argument

This commit is contained in:
Ryohei Ikegami 2017-04-04 09:36:01 +09:00
parent 9cb6bc098d
commit 4a7eec8f2d
7 changed files with 31 additions and 7 deletions

View file

@ -56,6 +56,7 @@ electron.ipcRenderer.on('ELECTRON_INTERNAL_RENDERER_ASYNC_WEB_FRAME_METHOD', (ev
let nodeIntegration = 'false'
let preloadScript = null
let isBackgroundPage = false
let appPath = null
for (let arg of process.argv) {
if (arg.indexOf('--guest-instance-id=') === 0) {
// This is a guest web view.
@ -69,6 +70,8 @@ for (let arg of process.argv) {
preloadScript = arg.substr(arg.indexOf('=') + 1)
} else if (arg === '--background-page') {
isBackgroundPage = true
} else if (arg.indexOf('--app-path=') === 0) {
appPath = arg.substr(arg.indexOf('=') + 1)
}
}
@ -117,10 +120,9 @@ if (nodeIntegration === 'true') {
global.__filename = __filename
global.__dirname = __dirname
if (window.location.protocol !== 'chrome-devtools:') {
if (appPath) {
// Search for module under the app directory
// (remote.app doesn't work in devtools)
module.paths = module.paths.concat(Module._nodeModulePaths(electron.remote.app.getAppPath()))
module.paths = module.paths.concat(Module._nodeModulePaths(appPath))
}
}