fix(downloading): fix recheck progress indication on start and finish

This commit is contained in:
Alexey Kasyanchuk 2018-06-27 18:26:14 +03:00
parent ea07872137
commit 1a23973ba2
2 changed files with 23 additions and 17 deletions

View File

@ -311,7 +311,7 @@ export default class Torrent extends Component {
</div>
}
{
this.state.downloading
(this.state.downloading || this.state.downloaded)
&&
<div className='row w100p inline text-nowrap' style={{maxWidth: 580}}>
<div style={{marginRight: 5, color: 'rgb(0, 188, 212)'}}>{__('downloading')}: </div>

View File

@ -591,22 +591,7 @@ module.exports = async ({
torrentClientHashMap[torrent.infoHash] = magnet
torrent.torrentObject = torrentObject
torrent.on('ready', () => {
console.log('start downloading', torrent.infoHash, 'to', torrent.path)
send('downloading', torrent.infoHash)
})
torrent.on('done', () => {
console.log('download done', torrent.infoHash)
send('downloadDone', torrent.infoHash)
})
let now = Date.now()
torrent.on('download', (bytes) => {
if(Date.now() - now < 100)
return
now = Date.now()
const progress = (bytes) => {
send('downloadProgress', torrent.infoHash, {
received: bytes,
downloaded: torrent.downloaded,
@ -614,6 +599,27 @@ module.exports = async ({
progress: torrent.progress,
timeRemaining: torrent.timeRemaining
})
}
torrent.on('ready', () => {
console.log('start downloading', torrent.infoHash, 'to', torrent.path)
send('downloading', torrent.infoHash)
})
torrent.on('done', () => {
console.log('download done', torrent.infoHash)
progress(0) // update progress
send('downloadDone', torrent.infoHash)
})
let now = Date.now()
progress(0) // immediately display progress
torrent.on('download', (bytes) => {
if(Date.now() - now < 100)
return
now = Date.now()
progress(bytes)
})
if(callback)