Skip to content

Commit

Permalink
fix(downloading): fix recheck progress indication on start and finish
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Jun 27, 2018
1 parent 125ce95 commit 048c0f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/torrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
20 changes: 13 additions & 7 deletions src/background/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,29 +591,35 @@ module.exports = async ({
torrentClientHashMap[torrent.infoHash] = magnet
torrent.torrentObject = torrentObject

const progress = (bytes) => {
send('downloadProgress', torrent.infoHash, {
received: bytes,
downloaded: torrent.downloaded,
downloadSpeed: torrent.downloadSpeed,
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()

send('downloadProgress', torrent.infoHash, {
received: bytes,
downloaded: torrent.downloaded,
downloadSpeed: torrent.downloadSpeed,
progress: torrent.progress,
timeRemaining: torrent.timeRemaining
})
progress(bytes)
})

if(callback)
Expand Down

0 comments on commit 048c0f6

Please sign in to comment.