From 765d3bde56ae9ae37f50b6d2ecdeecbc2ef4850f Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 19 Mar 2016 20:15:24 -0700 Subject: [PATCH] detect if app is running in production MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- config.js | 14 ++++++++++++++ main/index.js | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/config.js b/config.js index 6f6cce73..8095b556 100644 --- a/config.js +++ b/config.js @@ -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 + } +} diff --git a/main/index.js b/main/index.js index 042d47d2..9a6cae7d 100644 --- a/main/index.js +++ b/main/index.js @@ -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)