fix(download): fix download status in recent torrents
This commit is contained in:
parent
ac7e3cfe9f
commit
8b1fc513ad
@ -6,6 +6,8 @@ import Search from './search'
|
|||||||
import SelectField from 'material-ui/SelectField';
|
import SelectField from 'material-ui/SelectField';
|
||||||
import MenuItem from 'material-ui/MenuItem';
|
import MenuItem from 'material-ui/MenuItem';
|
||||||
|
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
export default class SearchPage extends Page {
|
export default class SearchPage extends Page {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
@ -14,10 +16,32 @@ export default class SearchPage extends Page {
|
|||||||
componentDidMount()
|
componentDidMount()
|
||||||
{
|
{
|
||||||
Search.instance().onSearchUpdate = () => this.forceUpdate()
|
Search.instance().onSearchUpdate = () => this.forceUpdate()
|
||||||
|
window.torrentSocket.emit('downloads', (downloads) => {
|
||||||
|
for(const torrent of downloads) {
|
||||||
|
const hash = torrent.torrentObject.hash;
|
||||||
|
delete torrent.torrentObject;
|
||||||
|
let needUpdate = false;
|
||||||
|
const updateValues = (target) => {
|
||||||
|
let index = _.findIndex(target, {hash});
|
||||||
|
if(index >= 0) {
|
||||||
|
target[index].download = torrent
|
||||||
|
needUpdate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateValues(Search.instance().searchTorrents);
|
||||||
|
updateValues(Search.instance().searchFiles);
|
||||||
|
if (needUpdate)
|
||||||
|
this.forceUpdate()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
componentWillUnmount()
|
componentWillUnmount()
|
||||||
{
|
{
|
||||||
Search.instance().onSearchUpdate = () => {}
|
Search.instance().onSearchUpdate = () => {}
|
||||||
|
for(const torrent of Search.instance().searchTorrents)
|
||||||
|
delete torrent.download
|
||||||
|
for(const torrent of Search.instance().searchFiles)
|
||||||
|
delete torrent.download
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
const orderText = (text, field) => {
|
const orderText = (text, field) => {
|
||||||
|
@ -169,26 +169,43 @@ export default class Torrent extends Component {
|
|||||||
downloadRemoveOnDone: false,
|
downloadRemoveOnDone: false,
|
||||||
downloadPaused: false,
|
downloadPaused: false,
|
||||||
}
|
}
|
||||||
|
downloadInited = false;
|
||||||
|
|
||||||
constructor(props)
|
constructor(props)
|
||||||
{
|
{
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
const download = props.download || props.torrent.download
|
|
||||||
if(download)
|
|
||||||
{
|
|
||||||
const { progress, downloaded, downloadSpeed, removeOnDone, paused } = download
|
|
||||||
this.state.downloadProgress = {
|
|
||||||
progress, downloaded, downloadSpeed
|
|
||||||
}
|
|
||||||
this.state.downloading = progress < 1
|
|
||||||
this.state.downloaded = progress === 1
|
|
||||||
this.state.downloadRemoveOnDone = removeOnDone
|
|
||||||
this.state.downloadPaused = paused
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const download = props.download || props.torrent.download;
|
||||||
|
this.updateDownload(download);
|
||||||
this.downloadPathInput = React.createRef();
|
this.downloadPathInput = React.createRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDownload(download)
|
||||||
|
{
|
||||||
|
if(download)
|
||||||
|
{
|
||||||
|
const { progress, downloaded, downloadSpeed, removeOnDone, paused } = download
|
||||||
|
this.state.downloadProgress = {
|
||||||
|
progress, downloaded, downloadSpeed
|
||||||
|
}
|
||||||
|
this.state.downloading = progress < 1
|
||||||
|
this.state.downloaded = progress === 1
|
||||||
|
this.state.downloadRemoveOnDone = removeOnDone
|
||||||
|
this.state.downloadPaused = paused
|
||||||
|
|
||||||
|
this.downloadInited = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps)
|
||||||
|
{
|
||||||
|
const download = this.props.download || this.props.torrent.download;
|
||||||
|
if(prevProps && !prevProps.download && download && !this.downloadInited) {
|
||||||
|
this.updateDownload(download);
|
||||||
|
this.forceUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount()
|
componentDidMount()
|
||||||
{
|
{
|
||||||
scrollBack()
|
scrollBack()
|
||||||
|
@ -36,15 +36,19 @@ describe("download", function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("check download exists in download tab", async function() {
|
it("check download exists in download tab", async function() {
|
||||||
this.timeout(8000);
|
this.timeout(10000);
|
||||||
const { app } = this
|
const { app } = this
|
||||||
await (await app.client.$('#downloadTab')).click()
|
await (await app.client.$('#downloadTab')).click()
|
||||||
const value = await (await app.client.$('.downloads-list .torrentRow .torrentName')).getText()
|
const value = await (await app.client.$('.downloads-list .torrentRow .torrentName')).getText()
|
||||||
assert.equal(value, 'Roblox_setup.exe')
|
assert.equal(value, 'Roblox_setup.exe')
|
||||||
console.log('download progress', await (await app.client.$('.torrentRow .progressDownloading')).getText());
|
let progress = parseInt(await (await app.client.$('.torrentRow .progressDownloading')).getText());
|
||||||
|
console.log('download progress', progress, '%');
|
||||||
// cancel in progress button must be exists
|
// cancel in progress button must be exists
|
||||||
assert(await (await app.client.$('.torrentRow .deleteDownloadBeforeFinish')).isExisting());
|
if (progress < 90) {
|
||||||
assert(await (await app.client.$('.torrentRow .pauseTorrent')).isExisting());
|
console.log('testing buttons')
|
||||||
|
assert(await (await app.client.$('.torrentRow .deleteDownloadBeforeFinish')).isExisting());
|
||||||
|
assert(await (await app.client.$('.torrentRow .pauseTorrent')).isExisting());
|
||||||
|
}
|
||||||
// back to recent search
|
// back to recent search
|
||||||
await (await app.client.$('#open-recent-search')).click()
|
await (await app.client.$('#open-recent-search')).click()
|
||||||
await app.client.$('.search-list')
|
await app.client.$('.search-list')
|
||||||
@ -57,7 +61,7 @@ describe("download", function() {
|
|||||||
console.log('download progress', await (await app.client.$('.torrentRow .progressDownloading')).getText());
|
console.log('download progress', await (await app.client.$('.torrentRow .progressDownloading')).getText());
|
||||||
await app.client.waitUntil(async () => {
|
await app.client.waitUntil(async () => {
|
||||||
return (await (await app.client.$('.torrentRow .progressDownloading')).getText()) === '100.0%'
|
return (await (await app.client.$('.torrentRow .progressDownloading')).getText()) === '100.0%'
|
||||||
}, 60000, 'expected that download will be finished', 200)
|
}, 80000, 'expected that download will be finished', 200)
|
||||||
// There is some time before button will be replaced
|
// There is some time before button will be replaced
|
||||||
await asyncWait(800);
|
await asyncWait(800);
|
||||||
|
|
||||||
@ -100,7 +104,7 @@ describe("download", function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("download file to folder", async function() {
|
it("download file to folder", async function() {
|
||||||
this.timeout(60000);
|
this.timeout(90000);
|
||||||
const { app } = this
|
const { app } = this
|
||||||
await (await app.client.$('#searchInput')).setValue('1413ba1915affdc3de7e1a81d6fdc32ef19395c9')
|
await (await app.client.$('#searchInput')).setValue('1413ba1915affdc3de7e1a81d6fdc32ef19395c9')
|
||||||
await (await app.client.$('#search')).click()
|
await (await app.client.$('#search')).click()
|
||||||
@ -115,7 +119,7 @@ describe("download", function() {
|
|||||||
// Downloading check
|
// Downloading check
|
||||||
await app.client.waitUntil(async () => {
|
await app.client.waitUntil(async () => {
|
||||||
return (await (await app.client.$('.torrentRow .progressDownloading')).getText()) === '100.0%'
|
return (await (await app.client.$('.torrentRow .progressDownloading')).getText()) === '100.0%'
|
||||||
}, 60000, 'expected that download will be finished', 200)
|
}, 80000, 'expected that download will be finished', 200)
|
||||||
// Check downloaded to directory
|
// Check downloaded to directory
|
||||||
assert(fs.existsSync(fileFolderTest));
|
assert(fs.existsSync(fileFolderTest));
|
||||||
assert.equal(await md5(fileFolderTest), '7df171da63e2013c9b17e1857615b192');
|
assert.equal(await md5(fileFolderTest), '7df171da63e2013c9b17e1857615b192');
|
||||||
|
Loading…
Reference in New Issue
Block a user