feat(download): cancel downloading
This commit is contained in:
parent
d320448903
commit
76651b6e02
@ -18,6 +18,7 @@ var moment = require('moment');
|
|||||||
import RefreshIndicator from 'material-ui/RefreshIndicator';
|
import RefreshIndicator from 'material-ui/RefreshIndicator';
|
||||||
let rating = require('./rating');
|
let rating = require('./rating');
|
||||||
import LinearProgress from 'material-ui/LinearProgress';
|
import LinearProgress from 'material-ui/LinearProgress';
|
||||||
|
import FlatButton from 'material-ui/FlatButton';
|
||||||
import {fileTypeDetect} from './content'
|
import {fileTypeDetect} from './content'
|
||||||
import {contentIcon} from './torrent'
|
import {contentIcon} from './torrent'
|
||||||
|
|
||||||
@ -247,11 +248,14 @@ export default class TorrentPage extends Page {
|
|||||||
}
|
}
|
||||||
window.torrentSocket.on('downloading', this.downloading);
|
window.torrentSocket.on('downloading', this.downloading);
|
||||||
|
|
||||||
this.downloadDone = (hash) => {
|
this.downloadDone = (hash, canceled) => {
|
||||||
if(this.props.hash != hash)
|
if(this.props.hash != hash)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.setState({downloading: false})
|
this.setState({
|
||||||
|
downloading: false,
|
||||||
|
askDownloading: !canceled
|
||||||
|
})
|
||||||
}
|
}
|
||||||
window.torrentSocket.on('downloadDone', this.downloadDone);
|
window.torrentSocket.on('downloadDone', this.downloadDone);
|
||||||
|
|
||||||
@ -402,6 +406,14 @@ export default class TorrentPage extends Page {
|
|||||||
mode="determinate"
|
mode="determinate"
|
||||||
value={this.state.downloadProgress && this.state.downloadProgress.progress * 100}
|
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>
|
||||||
}
|
}
|
||||||
<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>
|
<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>
|
||||||
|
@ -584,11 +584,14 @@ setInterval(() => {
|
|||||||
recive('download', (magnet) =>
|
recive('download', (magnet) =>
|
||||||
{
|
{
|
||||||
console.log('download', magnet)
|
console.log('download', magnet)
|
||||||
if(torrentClient.get(magnet))
|
if(torrentClient.get(magnet)) {
|
||||||
|
console.log('aready added')
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
torrentClient.add(magnet, {path: config.client.downloadPath}, (torrent) =>{
|
torrentClient.add(magnet, {path: config.client.downloadPath}, (torrent) =>{
|
||||||
torrentClientHashMap[torrent.infoHash] = magnet
|
torrentClientHashMap[torrent.infoHash] = magnet
|
||||||
|
console.log('start downloading', torrent.infoHash)
|
||||||
send('downloading', torrent.infoHash)
|
send('downloading', torrent.infoHash)
|
||||||
|
|
||||||
torrent.on('done', () => {
|
torrent.on('done', () => {
|
||||||
@ -622,7 +625,7 @@ setInterval(() => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
client.remove(id, (err) => {
|
torrentClient.remove(id, (err) => {
|
||||||
if(err)
|
if(err)
|
||||||
{
|
{
|
||||||
callback(false)
|
callback(false)
|
||||||
@ -630,6 +633,8 @@ setInterval(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete torrentClientHashMap[hash]
|
delete torrentClientHashMap[hash]
|
||||||
|
send('downloadDone', hash, true)
|
||||||
|
|
||||||
if(callback)
|
if(callback)
|
||||||
callback(true)
|
callback(true)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user