avoid updating past state changes

This commit is contained in:
Nils Maier 2019-08-21 00:15:49 +02:00
parent 1513f0b022
commit 7bb52bf869

View File

@ -225,6 +225,11 @@ export class DownloadItem extends EventEmitter {
this.emit("update"); this.emit("update");
} }
async queryState() {
const [state] = await downloads.search({id: this.manId});
return state;
}
adoptSize(state: any) { adoptSize(state: any) {
const { const {
bytesReceived, bytesReceived,
@ -239,7 +244,11 @@ export class DownloadItem extends EventEmitter {
if (!this.manId) { if (!this.manId) {
return; return;
} }
this.adoptSize((await downloads.search({id: this.manId})).pop()); const state = await this.queryState();
if (!this.manId) {
return;
}
this.adoptSize(state);
if (this.isFiltered) { if (this.isFiltered) {
this.owner.invalidateCell(this.filteredPosition, COL_PROGRESS); this.owner.invalidateCell(this.filteredPosition, COL_PROGRESS);
this.owner.invalidateCell(this.filteredPosition, COL_PER); this.owner.invalidateCell(this.filteredPosition, COL_PER);
@ -254,7 +263,11 @@ export class DownloadItem extends EventEmitter {
let v = 0; let v = 0;
try { try {
if (this.manId) { if (this.manId) {
this.adoptSize((await downloads.search({id: this.manId})).pop()); const state = await this.queryState();
if (!this.manId) {
return -1;
}
this.adoptSize(state);
if (!this.lastWritten) { if (!this.lastWritten) {
this.lastWritten = Math.max(0, this.written); this.lastWritten = Math.max(0, this.written);
return -1; return -1;