Skip to content

Commit

Permalink
feat(download): cancel downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Feb 8, 2018
1 parent 9ac5539 commit fd03491
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/app/torrent-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var moment = require('moment');
import RefreshIndicator from 'material-ui/RefreshIndicator';
let rating = require('./rating');
import LinearProgress from 'material-ui/LinearProgress';
import FlatButton from 'material-ui/FlatButton';
import {fileTypeDetect} from './content'
import {contentIcon} from './torrent'

Expand Down Expand Up @@ -247,11 +248,14 @@ export default class TorrentPage extends Page {
}
window.torrentSocket.on('downloading', this.downloading);

this.downloadDone = (hash) => {
this.downloadDone = (hash, canceled) => {
if(this.props.hash != hash)
return;

this.setState({downloading: false})
this.setState({
downloading: false,
askDownloading: !canceled
})
}
window.torrentSocket.on('downloadDone', this.downloadDone);

Expand Down Expand Up @@ -402,6 +406,14 @@ export default class TorrentPage extends Page {
mode="determinate"
value={this.state.downloadProgress && this.state.downloadProgress.progress * 100}
/>
<FlatButton
onClick={() => {
window.torrentSocket.emit('downloadCancel', this.torrent.hash)
}}
label="Cancel download"
secondary={true}
icon={<svg fill='rgb(255, 64, 129)' viewBox="0 0 18 18"><path d="M9 1C4.58 1 1 4.58 1 9s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm4 10.87L11.87 13 9 10.13 6.13 13 5 11.87 7.87 9 5 6.13 6.13 5 9 7.87 11.87 5 13 6.13 10.13 9 13 11.87z"/></svg>}
/>
</div>
}
<div className='fs0-75 pad0-75 center column' style={{color: 'rgba(0, 0, 0, 0.541176)'}}><div>BTIH:</div><div>{this.torrent.hash}</div></div>
Expand Down
9 changes: 7 additions & 2 deletions src/background/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,14 @@ setInterval(() => {
recive('download', (magnet) =>
{
console.log('download', magnet)
if(torrentClient.get(magnet))
if(torrentClient.get(magnet)) {
console.log('aready added')
return
}

torrentClient.add(magnet, {path: config.client.downloadPath}, (torrent) =>{
torrentClientHashMap[torrent.infoHash] = magnet
console.log('start downloading', torrent.infoHash)
send('downloading', torrent.infoHash)

torrent.on('done', () => {
Expand Down Expand Up @@ -622,14 +625,16 @@ setInterval(() => {
return
}

client.remove(id, (err) => {
torrentClient.remove(id, (err) => {
if(err)
{
callback(false)
return
}

delete torrentClientHashMap[hash]
send('downloadDone', hash, true)

if(callback)
callback(true)
})
Expand Down

0 comments on commit fd03491

Please sign in to comment.