added highest playback priority feature; added highest playback priority checkbox on preferences.
This commit is contained in:
@@ -26,6 +26,15 @@ module.exports = class PlaybackController {
|
|||||||
// * Stream, if not already fully downloaded
|
// * Stream, if not already fully downloaded
|
||||||
// * If no file index is provided, pick the default file to play
|
// * If no file index is provided, pick the default file to play
|
||||||
playFile (infoHash, index /* optional */) {
|
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({
|
this.state.location.go({
|
||||||
url: 'player',
|
url: 'player',
|
||||||
setup: (cb) => {
|
setup: (cb) => {
|
||||||
@@ -300,6 +309,11 @@ module.exports = class PlaybackController {
|
|||||||
|
|
||||||
ipcRenderer.send('onPlayerClose')
|
ipcRenderer.send('onPlayerClose')
|
||||||
|
|
||||||
|
// playback priority: resume previously paused downloads
|
||||||
|
if (this.state.saved.prefs.highestPlaybackPriority) {
|
||||||
|
dispatch('resumePausedTorrents')
|
||||||
|
}
|
||||||
|
|
||||||
this.update()
|
this.update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// TODO: use torrentKey, not infoHash
|
||||||
toggleTorrent (infoHash) {
|
toggleTorrent (infoHash) {
|
||||||
var torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
var torrentSummary = TorrentSummary.getByKey(this.state, infoHash)
|
||||||
|
|
||||||
|
// start
|
||||||
if (torrentSummary.status === 'paused') {
|
if (torrentSummary.status === 'paused') {
|
||||||
torrentSummary.status = 'new'
|
this.startTorrent(torrentSummary, true)
|
||||||
this.startTorrentingSummary(torrentSummary.torrentKey)
|
return
|
||||||
sound.play('ENABLE')
|
|
||||||
} else {
|
|
||||||
torrentSummary.status = 'paused'
|
|
||||||
ipcRenderer.send('wt-stop-torrenting', torrentSummary.infoHash)
|
|
||||||
sound.play('DISABLE')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
toggleTorrentFile (infoHash, index) {
|
||||||
|
|||||||
@@ -184,6 +184,8 @@ const dispatchHandlers = {
|
|||||||
'toggleSelectTorrent': (infoHash) => controllers.torrentList.toggleSelectTorrent(infoHash),
|
'toggleSelectTorrent': (infoHash) => controllers.torrentList.toggleSelectTorrent(infoHash),
|
||||||
'openTorrentContextMenu': (infoHash) => controllers.torrentList.openTorrentContextMenu(infoHash),
|
'openTorrentContextMenu': (infoHash) => controllers.torrentList.openTorrentContextMenu(infoHash),
|
||||||
'startTorrentingSummary': (torrentKey) => controllers.torrentList.startTorrentingSummary(torrentKey),
|
'startTorrentingSummary': (torrentKey) => controllers.torrentList.startTorrentingSummary(torrentKey),
|
||||||
|
'pauseAllTorrents': (params) => controllers.torrentList.pauseAll(params),
|
||||||
|
'resumePausedTorrents': () => controllers.torrentList.resumePausedTorrents(),
|
||||||
|
|
||||||
// Playback
|
// Playback
|
||||||
'playFile': (infoHash, index) => controllers.playback.playFile(infoHash, index),
|
'playFile': (infoHash, index) => controllers.playback.playFile(infoHash, index),
|
||||||
|
|||||||
@@ -60,6 +60,24 @@ class PreferencesPage extends React.Component {
|
|||||||
dispatch('updatePreferences', 'openExternalPlayer', !isChecked)
|
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 () {
|
externalPlayerPathSelector () {
|
||||||
const playerName = path.basename(
|
const playerName = path.basename(
|
||||||
this.props.state.unsaved.prefs.externalPlayerPath || 'VLC'
|
this.props.state.unsaved.prefs.externalPlayerPath || 'VLC'
|
||||||
@@ -129,6 +147,7 @@ class PreferencesPage extends React.Component {
|
|||||||
<PreferencesSection title='Playback'>
|
<PreferencesSection title='Playback'>
|
||||||
{this.openExternalPlayerCheckbox()}
|
{this.openExternalPlayerCheckbox()}
|
||||||
{this.externalPlayerPathSelector()}
|
{this.externalPlayerPathSelector()}
|
||||||
|
{this.highestPlaybackPriorityCheckbox()}
|
||||||
</PreferencesSection>
|
</PreferencesSection>
|
||||||
<PreferencesSection title='Default torrent app'>
|
<PreferencesSection title='Default torrent app'>
|
||||||
{this.setDefaultAppButton()}
|
{this.setDefaultAppButton()}
|
||||||
|
|||||||
Reference in New Issue
Block a user