From afe5151e289ec468693234fab27fce19376fa8b7 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 19 Mar 2016 19:23:35 -0700 Subject: [PATCH] Handle command line arguments --- main/index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/main/index.js b/main/index.js index 56080042..e1da3a45 100644 --- a/main/index.js +++ b/main/index.js @@ -8,6 +8,8 @@ var shortcuts = require('./shortcuts') var windows = require('./windows') var registerProtocolHandler = require('./register-protocol-handler') +var argv = process.argv.slice(2) + app.on('open-file', onOpen) app.on('open-url', onOpen) @@ -21,6 +23,12 @@ app.on('ready', function () { registerProtocolHandler() }) +app.on('ipcReady', function () { + argv.forEach(function (torrentId) { + windows.main.send('dispatch', 'onOpen', torrentId) + }) +}) + app.on('before-quit', function () { app.isQuitting = true }) @@ -44,12 +52,8 @@ ipc.init() function onOpen (e, torrentId) { e.preventDefault() if (app.ipcReady) { - onReadyOpen() - } else { - app.on('ipcReady', onReadyOpen) - } - function onReadyOpen () { windows.main.send('dispatch', 'onOpen', torrentId) - windows.main.focus() + } else { + argv.push(torrentId) } }