Files
webtorrent-desktop/main/index.js
Feross Aboukhadijeh 765d3bde56 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.
2016-03-19 20:32:19 -07:00

65 lines
1.4 KiB
JavaScript

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 argv = process.argv.slice(config.IS_PRODUCTION ? 1 : 2)
app.on('open-file', onOpen)
app.on('open-url', onOpen)
app.ipcReady = false // main window has finished loading and IPC is ready
app.isQuitting = false
app.on('ready', function () {
menu.init()
windows.createMainWindow()
shortcuts.init()
registerProtocolHandler()
})
app.on('ipcReady', function () {
windows.main.send('log', 'IS_PRODUCTION:', config.IS_PRODUCTION)
if (argv.length) {
windows.main.send('log', 'command line args:', process.argv)
}
argv.forEach(function (torrentId) {
windows.main.send('dispatch', 'onOpen', torrentId)
})
})
app.on('before-quit', function () {
app.isQuitting = true
})
app.on('activate', function () {
if (windows.main) {
windows.main.show()
} else {
windows.createMainWindow(menu)
}
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
ipc.init()
function onOpen (e, torrentId) {
e.preventDefault()
if (app.ipcReady) {
windows.main.send('dispatch', 'onOpen', torrentId)
} else {
argv.push(torrentId)
}
}