detect if app is running in production

If app is running in “production” (i.e. it has been packaged), then it
will be invoked with one less argument.

WebTorrent.exe arguments

vs.

electron.exe /path/to/app arguments

We need to detect this to correctly handle command line arguments.
This commit is contained in:
Feross Aboukhadijeh
2016-03-19 20:15:24 -07:00
parent 84a87dd1de
commit 765d3bde56
2 changed files with 19 additions and 3 deletions

View File

@@ -10,6 +10,8 @@ module.exports = {
INDEX: 'file://' + path.join(__dirname, 'renderer', 'index.html'),
IS_PRODUCTION: isProduction(),
SOUND_ADD: 'file://' + path.join(__dirname, 'static', 'sound', 'add.wav'),
SOUND_DELETE: 'file://' + path.join(__dirname, 'static', 'sound', 'delete.wav'),
SOUND_DISABLE: 'file://' + path.join(__dirname, 'static', 'sound', 'disable.wav'),
@@ -19,3 +21,15 @@ module.exports = {
SOUND_PLAY: 'file://' + path.join(__dirname, 'static', 'sound', 'play.wav'),
SOUND_STARTUP: 'file://' + path.join(__dirname, 'static', 'sound', 'startup.wav')
}
function isProduction () {
if (process.platform === 'darwin') {
return !/\/Electron\.app\/Contents\/MacOS\/Electron$/.test(process.execPath)
}
if (process.platform === 'win32') {
return !/\\electron\.exe$/.test(process.execPath)
}
if (process.platform === 'linux') {
// TODO
}
}

View File

@@ -2,13 +2,14 @@ var electron = require('electron')
var app = electron.app
var config = require('../config')
var ipc = require('./ipc')
var menu = require('./menu')
var registerProtocolHandler = require('./register-protocol-handler')
var shortcuts = require('./shortcuts')
var windows = require('./windows')
var registerProtocolHandler = require('./register-protocol-handler')
var argv = process.argv.slice(2)
var argv = process.argv.slice(config.IS_PRODUCTION ? 1 : 2)
app.on('open-file', onOpen)
app.on('open-url', onOpen)
@@ -24,8 +25,9 @@ app.on('ready', function () {
})
app.on('ipcReady', function () {
windows.main.send('log', 'IS_PRODUCTION:', config.IS_PRODUCTION)
if (argv.length) {
windows.main.send('log', 'command line args:', argv)
windows.main.send('log', 'command line args:', process.argv)
}
argv.forEach(function (torrentId) {
windows.main.send('dispatch', 'onOpen', torrentId)