diff --git a/src/app/torrent.js b/src/app/torrent.js
index ddd827b..6cc0618 100644
--- a/src/app/torrent.js
+++ b/src/app/torrent.js
@@ -311,7 +311,7 @@ export default class Torrent extends Component {
}
{
- this.state.downloading
+ (this.state.downloading || this.state.downloaded)
&&
{__('downloading')}:
diff --git a/src/background/api.js b/src/background/api.js
index 438218a..335d130 100644
--- a/src/background/api.js
+++ b/src/background/api.js
@@ -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)