added highest playback priority feature; added highest playback priority checkbox on preferences.

This commit is contained in:
Alberto Miranda
2016-08-27 03:35:53 -03:00
parent 89e77d34f4
commit bd41bd4db8
4 changed files with 99 additions and 7 deletions

View File

@@ -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()
}
}

View File

@@ -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) {

View File

@@ -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),

View File

@@ -60,6 +60,24 @@ class PreferencesPage extends React.Component {
dispatch('updatePreferences', 'openExternalPlayer', !isChecked)
}
highestPlaybackPriorityCheckbox () {
return (
<Preference>
<Checkbox
className='control'
checked={this.props.state.unsaved.prefs.highestPlaybackPriority}
label={'Highest Playback Priority'}
onCheck={this.handleHighestPlaybackPriorityChange}
/>
<p>Pauses all active torrents to allow playback to use all of the available bandwidth.</p>
</Preference>
)
}
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 {
<PreferencesSection title='Playback'>
{this.openExternalPlayerCheckbox()}
{this.externalPlayerPathSelector()}
{this.highestPlaybackPriorityCheckbox()}
</PreferencesSection>
<PreferencesSection title='Default torrent app'>
{this.setDefaultAppButton()}