feat(downloading): torrent pause feature

This commit is contained in:
Alexey Kasyanchuk
2018-06-30 04:15:12 +03:00
parent c086cd2087
commit 070119c352
6 changed files with 107 additions and 14 deletions

View File

@ -163,7 +163,8 @@ export default class Torrent extends Component {
downloaded: false,
startingDownloading: false,
downloadProgress: {},
downloadRemoveOnDone: false
downloadRemoveOnDone: false,
downloadPaused: false,
}
constructor(props)
{
@ -172,13 +173,14 @@ export default class Torrent extends Component {
const download = props.download || props.torrent.download
if(download)
{
const { progress, downloaded, downloadSpeed, removeOnDone } = download
const { progress, downloaded, downloadSpeed, removeOnDone, paused } = download
this.state.downloadProgress = {
progress, downloaded, downloadSpeed
}
this.state.downloading = progress < 1
this.state.downloaded = progress === 1
this.state.downloadRemoveOnDone = removeOnDone
this.state.downloadRemoveOnDone = removeOnDone
this.state.downloadPaused = paused
}
}
@ -224,7 +226,8 @@ export default class Torrent extends Component {
return;
this.setState({
downloadRemoveOnDone: options.removeOnDone
downloadRemoveOnDone: options.removeOnDone,
downloadPaused: options.paused
})
}
window.torrentSocket.on('downloadUpdate', this.downloadUpdate);
@ -250,7 +253,8 @@ export default class Torrent extends Component {
if(torrent.good > 0 || torrent.bad > 0)
torrentRating = Math.round(rating(torrent.good, torrent.bad) * 100);
const canDeleteDownloadAfterFinish = (this.state.downloading || this.state.startingDownloading) && !this.state.downloaded
const canDeleteDownloadAfterFinish = (this.state.downloading || this.state.startingDownloading) && !this.state.downloaded
const canPause = (this.state.downloading || this.state.startingDownloading)
return (
<div>
@ -354,7 +358,34 @@ export default class Torrent extends Component {
}
leftIcon={contentIcon(torrent.contentType, torrent.contentCategory, torrent.contentCategory != 'xxx' ? (torrent.peer ? '#6f5ee0' : 'grey') : (torrent.peer ? '#9083e2' : '#d3d3d3'))}
rightIcon={
<div className='row inline' style={{width: 63 + (canDeleteDownloadAfterFinish ? 40 : 0)}}>
<div className='row inline' style={{width: 63 + (canDeleteDownloadAfterFinish ? 40 : 0) + (canPause ? 40 : 0)}}>
{
// mark delete after finish
canPause
&&
<ToolTip hint={__('Pause torrent downloading')} right={true}>
<a href={`magnet:?xt=urn:btih:${torrent.hash}`}>
<svg style={{
height: '24px',
marginRight: 16,
fill: this.state.downloadPaused ? '#42f47a' : 'black'
}} onClick={(e) => {
e.preventDefault();
e.stopPropagation();
window.torrentSocket.emit('downloadUpdate', torrent.hash, {pause: 'switch'})
}} viewBox="0 0 438.536 438.536">
<g>
<path d="M164.453,0H18.276C13.324,0,9.041,1.807,5.425,5.424C1.808,9.04,0.001,13.322,0.001,18.271v401.991
c0,4.948,1.807,9.233,5.424,12.847c3.619,3.617,7.902,5.428,12.851,5.428h146.181c4.949,0,9.231-1.811,12.847-5.428
c3.617-3.613,5.424-7.898,5.424-12.847V18.271c0-4.952-1.807-9.231-5.428-12.847C173.685,1.807,169.402,0,164.453,0z"/>
<path d="M433.113,5.424C429.496,1.807,425.215,0,420.267,0H274.086c-4.949,0-9.237,1.807-12.847,5.424
c-3.621,3.615-5.432,7.898-5.432,12.847v401.991c0,4.948,1.811,9.233,5.432,12.847c3.609,3.617,7.897,5.428,12.847,5.428h146.181
c4.948,0,9.229-1.811,12.847-5.428c3.614-3.613,5.421-7.898,5.421-12.847V18.271C438.534,13.319,436.73,9.04,433.113,5.424z"/>
</g>
</svg>
</a>
</ToolTip>
}
{
// mark delete after finish
canDeleteDownloadAfterFinish
@ -364,7 +395,7 @@ export default class Torrent extends Component {
<svg style={{
height: '24px',
marginRight: 16,
fill: this.state.downloadRemoveOnDone ? 'red' : 'black'
fill: this.state.downloadRemoveOnDone ? '#f45c41' : 'black'
}} onClick={(e) => {
e.preventDefault();
e.stopPropagation();