From 6c197d8353a23994d3da82a8d569c1dc599ff772 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Tue, 20 Aug 2019 23:23:49 +0200 Subject: [PATCH] Update sizes more often --- uikit/lib/cell.ts | 2 ++ windows/manager/table.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/uikit/lib/cell.ts b/uikit/lib/cell.ts index eb2b4c9..6996755 100644 --- a/uikit/lib/cell.ts +++ b/uikit/lib/cell.ts @@ -46,6 +46,7 @@ export class Cell { } static makeCell(type: CellTypes, row: any, colid: number) { + /* eslint-disable @typescript-eslint/no-use-before-define */ switch (type) { case CellTypes.TYPE_TEXT: return new TextCell(row, colid); @@ -58,6 +59,7 @@ export class Cell { default: throw new Error(`Invalid cell type: ${type}`); } + /* eslint-enable @typescript-eslint/no-use-before-define */ } getCellIcon() { diff --git a/windows/manager/table.ts b/windows/manager/table.ts index 5a44d21..439b81c 100644 --- a/windows/manager/table.ts +++ b/windows/manager/table.ts @@ -37,6 +37,7 @@ import { downloads } from "../../lib/browser"; const TREE_CONFIG_VERSION = 2; const RUNNING_TIMEOUT = 1000; +const SIZES_TIMEOUT = 150; const COL_URL = 0; const COL_DOMAIN = 1; @@ -234,6 +235,18 @@ export class DownloadItem extends EventEmitter { 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() { if (this.state !== DownloadState.RUNNING) { return -1; @@ -284,6 +297,8 @@ export class DownloadTable extends VirtualTable { private runningTimer: any; + private sizesTimer: any; + private readonly globalStats: Stats; 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() { let sum = 0; for (const r of this.running) { @@ -931,6 +952,8 @@ export class DownloadTable extends VirtualTable { if (!this.running.size && this.runningTimer) { clearInterval(this.runningTimer); this.runningTimer = null; + clearInterval(this.sizesTimer); + this.sizesTimer = null; $("#statusSpeedContainer").classList.add("hidden"); } break; @@ -945,7 +968,10 @@ export class DownloadTable extends VirtualTable { if (!this.runningTimer) { this.runningTimer = setInterval( this.updateRunning.bind(this), RUNNING_TIMEOUT); + this.sizesTimer = setInterval( + this.updateSizes.bind(this), SIZES_TIMEOUT); this.updateRunning(); + this.updateSizes(); $("#statusSpeedContainer").classList.remove("hidden"); } break;