Update sizes more often

This commit is contained in:
Nils Maier 2019-08-20 23:23:49 +02:00
parent 64ad9a955f
commit 6c197d8353
2 changed files with 28 additions and 0 deletions

View File

@ -46,6 +46,7 @@ export class Cell {
} }
static makeCell(type: CellTypes, row: any, colid: number) { static makeCell(type: CellTypes, row: any, colid: number) {
/* eslint-disable @typescript-eslint/no-use-before-define */
switch (type) { switch (type) {
case CellTypes.TYPE_TEXT: case CellTypes.TYPE_TEXT:
return new TextCell(row, colid); return new TextCell(row, colid);
@ -58,6 +59,7 @@ export class Cell {
default: default:
throw new Error(`Invalid cell type: ${type}`); throw new Error(`Invalid cell type: ${type}`);
} }
/* eslint-enable @typescript-eslint/no-use-before-define */
} }
getCellIcon() { getCellIcon() {

View File

@ -37,6 +37,7 @@ import { downloads } from "../../lib/browser";
const TREE_CONFIG_VERSION = 2; const TREE_CONFIG_VERSION = 2;
const RUNNING_TIMEOUT = 1000; const RUNNING_TIMEOUT = 1000;
const SIZES_TIMEOUT = 150;
const COL_URL = 0; const COL_URL = 0;
const COL_DOMAIN = 1; const COL_DOMAIN = 1;
@ -234,6 +235,18 @@ export class DownloadItem extends EventEmitter {
this.totalSize = Math.max(0, fileSize >= 0 ? fileSize : totalBytes); this.totalSize = Math.max(0, fileSize >= 0 ? fileSize : totalBytes);
} }
async updateSizes() {
if (!this.manId) {
return;
}
this.adoptSize((await downloads.search({id: this.manId})).pop());
if (this.isFiltered) {
this.owner.invalidateCell(this.filteredPosition, COL_PROGRESS);
this.owner.invalidateCell(this.filteredPosition, COL_PER);
this.owner.invalidateCell(this.filteredPosition, COL_SIZE);
}
}
async updateStats() { async updateStats() {
if (this.state !== DownloadState.RUNNING) { if (this.state !== DownloadState.RUNNING) {
return -1; return -1;
@ -284,6 +297,8 @@ export class DownloadTable extends VirtualTable {
private runningTimer: any; private runningTimer: any;
private sizesTimer: any;
private readonly globalStats: Stats; private readonly globalStats: Stats;
private readonly downloads: FilteredCollection; private readonly downloads: FilteredCollection;
@ -552,6 +567,12 @@ export class DownloadTable extends VirtualTable {
} }
} }
async updateSizes() {
for (const r of this.running) {
await r.updateSizes();
}
}
async updateRunning() { async updateRunning() {
let sum = 0; let sum = 0;
for (const r of this.running) { for (const r of this.running) {
@ -931,6 +952,8 @@ export class DownloadTable extends VirtualTable {
if (!this.running.size && this.runningTimer) { if (!this.running.size && this.runningTimer) {
clearInterval(this.runningTimer); clearInterval(this.runningTimer);
this.runningTimer = null; this.runningTimer = null;
clearInterval(this.sizesTimer);
this.sizesTimer = null;
$("#statusSpeedContainer").classList.add("hidden"); $("#statusSpeedContainer").classList.add("hidden");
} }
break; break;
@ -945,7 +968,10 @@ export class DownloadTable extends VirtualTable {
if (!this.runningTimer) { if (!this.runningTimer) {
this.runningTimer = setInterval( this.runningTimer = setInterval(
this.updateRunning.bind(this), RUNNING_TIMEOUT); this.updateRunning.bind(this), RUNNING_TIMEOUT);
this.sizesTimer = setInterval(
this.updateSizes.bind(this), SIZES_TIMEOUT);
this.updateRunning(); this.updateRunning();
this.updateSizes();
$("#statusSpeedContainer").classList.remove("hidden"); $("#statusSpeedContainer").classList.remove("hidden");
} }
break; break;