diff --git a/src/app/download-page.js b/src/app/download-page.js
index 781d788..17d64e6 100644
--- a/src/app/download-page.js
+++ b/src/app/download-page.js
@@ -45,8 +45,9 @@ export default class TopPage extends Page {
}} />
{
- this.downloads.map((download, index) => {
- return
+ this.downloads.map((torrentDownload, index) => {
+ const {torrentObject: torrent, ...download} = torrentDownload
+ return
})
}
diff --git a/src/app/torrent.js b/src/app/torrent.js
index 6fdb3d0..e6212f2 100644
--- a/src/app/torrent.js
+++ b/src/app/torrent.js
@@ -171,6 +171,7 @@ export default class Torrent extends Component {
this.state.downloadProgress = {
progress, downloaded, downloadSpeed
}
+ this.state.downloading = true
}
}
componentDidMount()
@@ -303,21 +304,21 @@ export default class Torrent extends Component {
/>
= 50 ? '#00E676' : '#FF3D00', width: '190px'}}>{__('Torrent rating')}: {torrentRating}%
- }
- {
- this.state.downloading
- &&
-
-
{__('downloading')}:
-
-
{this.state.downloadProgress && (this.state.downloadProgress.progress * 100).toFixed(1)}%
-
{this.state.downloadProgress && formatBytes(this.state.downloadProgress.downloadSpeed || 0, 0)}/s
-
- }
+ }
+ {
+ this.state.downloading
+ &&
+
+
{__('downloading')}:
+
+
{this.state.downloadProgress && (this.state.downloadProgress.progress * 100).toFixed(1)}%
+
{this.state.downloadProgress && formatBytes(this.state.downloadProgress.downloadSpeed || 0, 0)}/s
+
+ }
}
diff --git a/src/background/api.js b/src/background/api.js
index 2948c9d..49cd749 100644
--- a/src/background/api.js
+++ b/src/background/api.js
@@ -585,31 +585,33 @@ module.exports = async ({
return
}
- torrentClient.add(magnet, {path: config.client.downloadPath}, (torrent) =>{
- torrentClientHashMap[torrent.infoHash] = magnet
- torrent.torrentObject = torrentObject
+ const torrent = torrentClient.add(magnet, {path: config.client.downloadPath})
+ torrentClientHashMap[torrent.infoHash] = magnet
+ torrent.torrentObject = torrentObject
+
+ torrent.on('torrent', () => {
console.log('start downloading', torrent.infoHash)
send('downloading', torrent.infoHash)
+ })
- torrent.on('done', () => {
- console.log('download done', torrent.infoHash)
- delete torrentClientHashMap[torrent.infoHash]
- send('downloadDone', torrent.infoHash)
- })
+ torrent.on('done', () => {
+ console.log('download done', torrent.infoHash)
+ delete torrentClientHashMap[torrent.infoHash]
+ send('downloadDone', torrent.infoHash)
+ })
- let now = Date.now()
- torrent.on('download', (bytes) => {
- if(Date.now() - now < 100)
- return
- now = Date.now()
+ let now = Date.now()
+ 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
- })
+ send('downloadProgress', torrent.infoHash, {
+ received: bytes,
+ downloaded: torrent.downloaded,
+ downloadSpeed: torrent.downloadSpeed,
+ progress: torrent.progress,
+ timeRemaining: torrent.timeRemaining
})
})
});