From dfe8c3eb6b5211fb4aa2192d230f6bdfa3692a92 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 11 May 2016 17:52:18 +0200 Subject: [PATCH 1/3] remove unneeded console.log --- crash-reporter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/crash-reporter.js b/crash-reporter.js index c470e79a..359f5645 100644 --- a/crash-reporter.js +++ b/crash-reporter.js @@ -11,5 +11,4 @@ function init () { productName: config.APP_NAME, submitURL: config.CRASH_REPORT_URL }) - console.log('crash reporter started') } From 1eb55040296037b700b909b164a6f9f7ee53980b Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 11 May 2016 17:56:20 +0200 Subject: [PATCH 2/3] move console.time/timeEnd to same file --- index.js | 1 - main/index.js | 3 +++ main/ipc.js | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 151415b0..140c9430 100644 --- a/index.js +++ b/index.js @@ -1,2 +1 @@ -console.time('init') require('./main') diff --git a/main/index.js b/main/index.js index e26d055c..a496dba1 100644 --- a/main/index.js +++ b/main/index.js @@ -1,3 +1,5 @@ +console.time('init') + var electron = require('electron') var app = electron.app @@ -67,6 +69,7 @@ function init () { app.on('ipcReady', function () { log('Command line args:', argv) processArgv(argv) + console.timeEnd('init') }) app.on('before-quit', function (e) { diff --git a/main/ipc.js b/main/ipc.js index dca4a6ac..e5b0a3a8 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -25,10 +25,9 @@ var vlcProcess function init () { ipcMain.on('ipcReady', function (e) { + windows.main.show() app.ipcReady = true app.emit('ipcReady') - windows.main.show() - console.timeEnd('init') }) ipcMain.on('ipcReadyWebTorrent', function (e) { From 9eeb8133af479d48f04d67949b2c99b23ec5c24a Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 11 May 2016 18:36:20 +0200 Subject: [PATCH 3/3] Fix duplicate torrent handling WebTorrent 0.91 changed how duplicate torrents are handled, which broke handling in WebTorrent Desktop. After this PR: - No more try-catch on client.add -- this has never thrown errors. - No check for duplicate torrent.key value since client.add no longer returns the same torrent object when adding a duplicate torrent. It emits 'error' instead, and that case is already handled :) --- renderer/index.js | 18 +++++++++--------- renderer/webtorrent.js | 21 ++++++--------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/renderer/index.js b/renderer/index.js index 2779780c..f7e076a9 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -724,16 +724,16 @@ function torrentWarning (torrentKey, message) { } function torrentError (torrentKey, message) { - var torrentSummary = getTorrentSummary(torrentKey) + // TODO: WebTorrent needs semantic errors + if (message.startsWith('Cannot add duplicate torrent')) { + // Remove infohash from the message + message = 'Cannot add duplicate torrent' + } + onError(message) - // TODO: WebTorrent should have semantic errors - if (message.startsWith('There is already a swarm')) { - onError(new Error('Can\'t add duplicate torrent')) - } else if (!torrentSummary) { - onError(message) - } else { - console.log('error, stopping torrent %s (%s):\n\t%o', - torrentSummary.name, torrentSummary.infoHash, message) + var torrentSummary = getTorrentSummary(torrentKey) + if (torrentSummary) { + console.log('Pausing torrent %s due to error: %s', torrentSummary.infoHash, message) torrentSummary.status = 'paused' update() } diff --git a/renderer/webtorrent.js b/renderer/webtorrent.js index d90458fc..385b4b45 100644 --- a/renderer/webtorrent.js +++ b/renderer/webtorrent.js @@ -68,23 +68,14 @@ function init () { // See https://github.com/feross/webtorrent/blob/master/docs/api.md#clientaddtorrentid-opts-function-ontorrent-torrent- function startTorrenting (torrentKey, torrentID, path, fileModtimes) { console.log('starting torrent %s: %s', torrentKey, torrentID) - var torrent - try { - torrent = client.add(torrentID, { - path: path, - fileModtimes: fileModtimes - }) - } catch (err) { - return ipc.send('wt-error', torrentKey, err.message) - } - // If we add a duplicate magnet URI or infohash, WebTorrent returns the - // existing torrent object! (If we add a duplicate torrent file, it creates a - // new torrent object and raises an error later.) Workaround: - if (torrent.key) { - return ipc.send('wt-error', torrentKey, 'Can\'t add duplicate torrent') - } + + var torrent = client.add(torrentID, { + path: path, + fileModtimes: fileModtimes + }) torrent.key = torrentKey addTorrentEvents(torrent) + return torrent }