Cleanup argument handling in main

This commit is contained in:
Feross Aboukhadijeh
2016-06-01 00:20:11 -07:00
parent dac34541d6
commit e88ddd648b

View File

@@ -103,13 +103,12 @@ function onOpen (e, torrentId) {
e.preventDefault()
if (app.ipcReady) {
windows.main.dispatch('onOpen', torrentId)
// Magnet links opened from Chrome won't focus the app without a setTimeout.
// The confirmation dialog Chrome shows causes Chrome to steal back the focus.
// Electron issue: https://github.com/atom/electron/issues/4338
setTimeout(function () {
windows.main.show()
}, 100)
setTimeout(() => windows.main.show(), 100)
processArgv([ torrentId ])
} else {
argv.push(torrentId)
}
@@ -133,7 +132,7 @@ function sliceArgv (argv) {
}
function processArgv (argv) {
var paths = []
var torrentIds = []
argv.forEach(function (arg) {
if (arg === '-n') {
dialog.openSeedDirectory()
@@ -145,10 +144,10 @@ function processArgv (argv) {
// Ignore OS X launchd "process serial number" argument
// Issue: https://github.com/feross/webtorrent-desktop/issues/214
} else {
paths.push(arg)
torrentIds.push(arg)
}
})
if (paths.length > 0) {
windows.main.dispatch('onOpen', paths)
if (torrentIds.length > 0) {
windows.main.dispatch('onOpen', torrentIds)
}
}