From 49fd82291032029fde51b119b202586c8a3be4ab Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Tue, 8 Mar 2016 16:43:26 -0800 Subject: [PATCH] Fix seeding functionality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix for small oversight in @dcposch’s recent changes. Broken when adding the distinction between active and inactive torrents. Please code review, @dcposch --- renderer/index.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/renderer/index.js b/renderer/index.js index 10ced910..e577d0a2 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -315,14 +315,20 @@ function addTorrent (torrentId) { var torrent = startTorrenting(torrentId) - // If torrentId is a torrent file, wait for WebTorrent to finish reading it - if (!torrent.infoHash) torrent.on('infoHash', addTorrentToList) - else addTorrentToList() + addTorrentToList(torrent) +} - function addTorrentToList () { - if (getTorrentSummary(torrent.infoHash)) { - return // Skip, torrent is already in state.saved - } +function addTorrentToList (torrent) { + if (getTorrentSummary(torrent.infoHash)) { + return // Skip, torrent is already in state.saved + } + + // If torrentId is a remote torrent (filesystem path, http url, etc.), wait for + // WebTorrent to finish reading it + if (torrent.infoHash) onInfoHash() + else torrent.on('infoHash', onInfoHash) + + function onInfoHash () { state.saved.torrents.push({ status: 'new', name: torrent.name, @@ -353,6 +359,7 @@ function stopTorrenting (infoHash) { function seed (files) { if (files.length === 0) return var torrent = state.client.seed(files) + addTorrentToList(torrent) addTorrentEvents(torrent) }