From bd41bd4db81927ff5834b89286f2dd7ea13d48f9 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Sat, 27 Aug 2016 03:35:53 -0300 Subject: [PATCH 1/7] added highest playback priority feature; added highest playback priority checkbox on preferences. --- .../controllers/playback-controller.js | 14 ++++ .../controllers/torrent-list-controller.js | 71 +++++++++++++++++-- src/renderer/main.js | 2 + src/renderer/pages/PreferencesPage.js | 19 +++++ 4 files changed, 99 insertions(+), 7 deletions(-) diff --git a/src/renderer/controllers/playback-controller.js b/src/renderer/controllers/playback-controller.js index d1c38153..523d6f3c 100644 --- a/src/renderer/controllers/playback-controller.js +++ b/src/renderer/controllers/playback-controller.js @@ -26,6 +26,15 @@ module.exports = class PlaybackController { // * Stream, if not already fully downloaded // * If no file index is provided, pick the default file to play playFile (infoHash, index /* optional */) { + // playback priority: pause all active torrents + if (this.state.saved.prefs.highestPlaybackPriority) { + var params = { + filter: {status: /downloading|seeding/}, + excluded: [infoHash] + } + dispatch('pauseAllTorrents', params) + } + this.state.location.go({ url: 'player', setup: (cb) => { @@ -300,6 +309,11 @@ module.exports = class PlaybackController { ipcRenderer.send('onPlayerClose') + // playback priority: resume previously paused downloads + if (this.state.saved.prefs.highestPlaybackPriority) { + dispatch('resumePausedTorrents') + } + this.update() } } diff --git a/src/renderer/controllers/torrent-list-controller.js b/src/renderer/controllers/torrent-list-controller.js index c155fbcf..50012451 100644 --- a/src/renderer/controllers/torrent-list-controller.js +++ b/src/renderer/controllers/torrent-list-controller.js @@ -103,18 +103,75 @@ module.exports = class TorrentListController { } } + pauseAll ({filter, excluded}) { + console.log('--- pause all') + this.state.saved.torrents.map((torrent) => { + // "excluded" is an array of torrents that should not be paused + if (excluded) { + var isExcluded = excluded.some((excludeInfoHash) => { + if (excludeInfoHash === torrent.infoHash) return true + }) + if (isExcluded) return + } + + // don't play sounds when pausing all + var wasPaused = this.pauseTorrent(torrent, false, filter) + + // if torrent was paused add it to paused torrents collection + // we will use this collection to resume downloading when playback stops + if (wasPaused) this.state.saved.pausedTorrents.push(torrent.infoHash) + }) + } + + resumePausedTorrents () { + console.log('--- resume paused torrents') + this.state.saved.pausedTorrents.map((infoHash) => { + var torrentSummary = TorrentSummary.getByKey(this.state, infoHash) + this.startTorrent(torrentSummary) + }) + + // reset paused torrents + this.state.saved.pausedTorrents = [] + } + // TODO: use torrentKey, not infoHash toggleTorrent (infoHash) { var torrentSummary = TorrentSummary.getByKey(this.state, infoHash) + + // start if (torrentSummary.status === 'paused') { - torrentSummary.status = 'new' - this.startTorrentingSummary(torrentSummary.torrentKey) - sound.play('ENABLE') - } else { - torrentSummary.status = 'paused' - ipcRenderer.send('wt-stop-torrenting', torrentSummary.infoHash) - sound.play('DISABLE') + this.startTorrent(torrentSummary, true) + return } + + // pause + this.pauseTorrent(torrentSummary, true) + } + + startTorrent (torrentSummary, playSound) { + torrentSummary.status = 'new' + this.startTorrentingSummary(torrentSummary.torrentKey) + + if (playSound) sound.play('ENABLE') + } + + pauseTorrent (torrentSummary, playSound, filter) { + if (filter && !this.matchesFilter(torrentSummary, filter)) return false + + torrentSummary.status = 'paused' + ipcRenderer.send('wt-stop-torrenting', torrentSummary.infoHash) + + if (playSound) sound.play('DISABLE') + return true + } + + matchesFilter (torrentSummary, filter) { + var keys = Object.keys(filter) + var matches = keys.some((key) => { + if (!torrentSummary[key].match(filter[key])) return false + return true + }) + return matches } toggleTorrentFile (infoHash, index) { diff --git a/src/renderer/main.js b/src/renderer/main.js index e9ed6cee..ccab7261 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -184,6 +184,8 @@ const dispatchHandlers = { 'toggleSelectTorrent': (infoHash) => controllers.torrentList.toggleSelectTorrent(infoHash), 'openTorrentContextMenu': (infoHash) => controllers.torrentList.openTorrentContextMenu(infoHash), 'startTorrentingSummary': (torrentKey) => controllers.torrentList.startTorrentingSummary(torrentKey), + 'pauseAllTorrents': (params) => controllers.torrentList.pauseAll(params), + 'resumePausedTorrents': () => controllers.torrentList.resumePausedTorrents(), // Playback 'playFile': (infoHash, index) => controllers.playback.playFile(infoHash, index), diff --git a/src/renderer/pages/PreferencesPage.js b/src/renderer/pages/PreferencesPage.js index 79642979..f79a8f3b 100644 --- a/src/renderer/pages/PreferencesPage.js +++ b/src/renderer/pages/PreferencesPage.js @@ -60,6 +60,24 @@ class PreferencesPage extends React.Component { dispatch('updatePreferences', 'openExternalPlayer', !isChecked) } + highestPlaybackPriorityCheckbox () { + return ( + + +

Pauses all active torrents to allow playback to use all of the available bandwidth.

+
+ ) + } + + handleHighestPlaybackPriorityChange (e, isChecked) { + dispatch('updatePreferences', 'highestPlaybackPriority', isChecked) + } + externalPlayerPathSelector () { const playerName = path.basename( this.props.state.unsaved.prefs.externalPlayerPath || 'VLC' @@ -129,6 +147,7 @@ class PreferencesPage extends React.Component { {this.openExternalPlayerCheckbox()} {this.externalPlayerPathSelector()} + {this.highestPlaybackPriorityCheckbox()} {this.setDefaultAppButton()} From e483263d70c28875849896265246218a0bcdd082 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Sat, 27 Aug 2016 03:36:28 -0300 Subject: [PATCH 2/7] removed logging --- src/renderer/controllers/torrent-list-controller.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/renderer/controllers/torrent-list-controller.js b/src/renderer/controllers/torrent-list-controller.js index 50012451..6a743098 100644 --- a/src/renderer/controllers/torrent-list-controller.js +++ b/src/renderer/controllers/torrent-list-controller.js @@ -104,7 +104,6 @@ module.exports = class TorrentListController { } pauseAll ({filter, excluded}) { - console.log('--- pause all') this.state.saved.torrents.map((torrent) => { // "excluded" is an array of torrents that should not be paused if (excluded) { @@ -124,7 +123,6 @@ module.exports = class TorrentListController { } resumePausedTorrents () { - console.log('--- resume paused torrents') this.state.saved.pausedTorrents.map((infoHash) => { var torrentSummary = TorrentSummary.getByKey(this.state, infoHash) this.startTorrent(torrentSummary) From 4cdc3085ff689036e803717ca77a224c8e887202 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Sat, 27 Aug 2016 03:55:23 -0300 Subject: [PATCH 3/7] not pausing active torrents when playing an already downloaded torrent. --- .../controllers/playback-controller.js | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/renderer/controllers/playback-controller.js b/src/renderer/controllers/playback-controller.js index 523d6f3c..1cd8d2a2 100644 --- a/src/renderer/controllers/playback-controller.js +++ b/src/renderer/controllers/playback-controller.js @@ -26,14 +26,7 @@ module.exports = class PlaybackController { // * Stream, if not already fully downloaded // * If no file index is provided, pick the default file to play playFile (infoHash, index /* optional */) { - // playback priority: pause all active torrents - if (this.state.saved.prefs.highestPlaybackPriority) { - var params = { - filter: {status: /downloading|seeding/}, - excluded: [infoHash] - } - dispatch('pauseAllTorrents', params) - } + this.pauseActiveTorrents(infoHash) this.state.location.go({ url: 'player', @@ -47,6 +40,24 @@ module.exports = class PlaybackController { }) } + pauseActiveTorrents (infoHash) { + // playback priority: pause all active torrents if needed + if (this.state.saved.prefs.highestPlaybackPriority) { + // do not pause active torrents if playing a fully downloaded torrent + var torrentSummary = TorrentSummary.getByKey(this.state, infoHash) + if (torrentSummary.status === 'seeding') { + console.log('--- NOT PAUSING active torrents for already downloaded torrent!') + return + } + + var params = { + filter: {status: /downloading|seeding/}, + excluded: [infoHash] + } + dispatch('pauseAllTorrents', params) + } + } + // Open a file in OS default app. openItem (infoHash, index) { var torrentSummary = TorrentSummary.getByKey(this.state, infoHash) From 1e5ac1df9ca5e2da5e28732b7e12b578e6dda637 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Sat, 27 Aug 2016 03:56:08 -0300 Subject: [PATCH 4/7] removed logging --- src/renderer/controllers/playback-controller.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/renderer/controllers/playback-controller.js b/src/renderer/controllers/playback-controller.js index 1cd8d2a2..668c98a7 100644 --- a/src/renderer/controllers/playback-controller.js +++ b/src/renderer/controllers/playback-controller.js @@ -45,10 +45,7 @@ module.exports = class PlaybackController { if (this.state.saved.prefs.highestPlaybackPriority) { // do not pause active torrents if playing a fully downloaded torrent var torrentSummary = TorrentSummary.getByKey(this.state, infoHash) - if (torrentSummary.status === 'seeding') { - console.log('--- NOT PAUSING active torrents for already downloaded torrent!') - return - } + if (torrentSummary.status === 'seeding') return var params = { filter: {status: /downloading|seeding/}, From 44a0f760deeb30dccd99d7b155e14a77a8894f58 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 30 Aug 2016 12:09:23 -0300 Subject: [PATCH 5/7] Resuming paused torrents when streaming torrent finishes downloading (wt-done). --- src/renderer/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/renderer/main.js b/src/renderer/main.js index ccab7261..bc0ac378 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -281,6 +281,7 @@ function setupIpc () { ipcRenderer.on('wt-infohash', (e, ...args) => tc.torrentInfoHash(...args)) ipcRenderer.on('wt-metadata', (e, ...args) => tc.torrentMetadata(...args)) ipcRenderer.on('wt-done', (e, ...args) => tc.torrentDone(...args)) + ipcRenderer.on('wt-done', () => controllers.torrentList.resumePausedTorrents()) ipcRenderer.on('wt-warning', (e, ...args) => tc.torrentWarning(...args)) ipcRenderer.on('wt-error', (e, ...args) => tc.torrentError(...args)) From 043f81996e182fc115596828f9647f9670cbd736 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 14 Mar 2017 19:50:49 -0300 Subject: [PATCH 6/7] fixed styling issues; returning early in pauseActiveTorrents. --- src/renderer/controllers/playback-controller.js | 12 ++++++------ src/renderer/controllers/torrent-list-controller.js | 2 +- src/renderer/pages/preferences-page.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/renderer/controllers/playback-controller.js b/src/renderer/controllers/playback-controller.js index 9749032e..8288baa3 100644 --- a/src/renderer/controllers/playback-controller.js +++ b/src/renderer/controllers/playback-controller.js @@ -88,13 +88,13 @@ module.exports = class PlaybackController { pauseActiveTorrents (infoHash) { // Playback Priority: pause all active torrents if needed. - if (this.state.saved.prefs.highestPlaybackPriority) { - // Do not pause active torrents if playing a fully downloaded torrent. - var torrentSummary = TorrentSummary.getByKey(this.state, infoHash) - if (torrentSummary.status === 'seeding') return + if (!this.state.saved.prefs.highestPlaybackPriority) return - dispatch('prioritizeTorrent', infoHash) - } + // Do not pause active torrents if playing a fully downloaded torrent. + const torrentSummary = TorrentSummary.getByKey(this.state, infoHash) + if (torrentSummary.status === 'seeding') return + + dispatch('prioritizeTorrent', infoHash) } // Play next file in list (if any) diff --git a/src/renderer/controllers/torrent-list-controller.js b/src/renderer/controllers/torrent-list-controller.js index de95c1c5..12cee063 100644 --- a/src/renderer/controllers/torrent-list-controller.js +++ b/src/renderer/controllers/torrent-list-controller.js @@ -122,7 +122,7 @@ module.exports = class TorrentListController { this.startTorrentingSummary(torrentSummary.torrentKey) sound.play('ENABLE') return - } + } this.pauseTorrent(torrentSummary, true) } diff --git a/src/renderer/pages/preferences-page.js b/src/renderer/pages/preferences-page.js index e547f4d3..bf729141 100644 --- a/src/renderer/pages/preferences-page.js +++ b/src/renderer/pages/preferences-page.js @@ -69,7 +69,7 @@ class PreferencesPage extends React.Component { className='control' checked={this.props.state.unsaved.prefs.highestPlaybackPriority} label={'Highest Playback Priority'} - onCheck={this.handleHighestPlaybackPriorityChange} + onCheck={this.handleHighestPlaybackPriorityChange} />

Pauses all active torrents to allow playback to use all of the available bandwidth.

From 99f4fc96bf95c04b9af247b40e1b028c07e6788b Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 14 Mar 2017 19:52:29 -0300 Subject: [PATCH 7/7] Fixed resuming when downloading finishes. --- src/renderer/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/main.js b/src/renderer/main.js index 247743da..7acb24f5 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -356,7 +356,7 @@ function setupIpc () { ipcRenderer.on('wt-infohash', (e, ...args) => tc.torrentInfoHash(...args)) ipcRenderer.on('wt-metadata', (e, ...args) => tc.torrentMetadata(...args)) ipcRenderer.on('wt-done', (e, ...args) => tc.torrentDone(...args)) - ipcRenderer.on('wt-done', () => controllers.torrentList.resumePausedTorrents()) + ipcRenderer.on('wt-done', () => controllers.torrentList().resumePausedTorrents()) ipcRenderer.on('wt-warning', (e, ...args) => tc.torrentWarning(...args)) ipcRenderer.on('wt-error', (e, ...args) => tc.torrentError(...args))