Handle command line arguments

This commit is contained in:
Feross Aboukhadijeh
2016-03-19 19:23:35 -07:00
parent e70e32c5f8
commit afe5151e28

View File

@@ -8,6 +8,8 @@ var shortcuts = require('./shortcuts')
var windows = require('./windows') var windows = require('./windows')
var registerProtocolHandler = require('./register-protocol-handler') var registerProtocolHandler = require('./register-protocol-handler')
var argv = process.argv.slice(2)
app.on('open-file', onOpen) app.on('open-file', onOpen)
app.on('open-url', onOpen) app.on('open-url', onOpen)
@@ -21,6 +23,12 @@ app.on('ready', function () {
registerProtocolHandler() registerProtocolHandler()
}) })
app.on('ipcReady', function () {
argv.forEach(function (torrentId) {
windows.main.send('dispatch', 'onOpen', torrentId)
})
})
app.on('before-quit', function () { app.on('before-quit', function () {
app.isQuitting = true app.isQuitting = true
}) })
@@ -44,12 +52,8 @@ ipc.init()
function onOpen (e, torrentId) { function onOpen (e, torrentId) {
e.preventDefault() e.preventDefault()
if (app.ipcReady) { if (app.ipcReady) {
onReadyOpen()
} else {
app.on('ipcReady', onReadyOpen)
}
function onReadyOpen () {
windows.main.send('dispatch', 'onOpen', torrentId) windows.main.send('dispatch', 'onOpen', torrentId)
windows.main.focus() } else {
argv.push(torrentId)
} }
} }