diff --git a/src/components/DownloadItem.tsx b/src/components/DownloadItem.tsx index b7a78aa..a622530 100644 --- a/src/components/DownloadItem.tsx +++ b/src/components/DownloadItem.tsx @@ -8,6 +8,7 @@ import { canPauseDownload, canStartDownload, startActionLabel } from '../utils/d import { isActiveDownloadStatus } from '../utils/downloads'; import { downloadProgressColorClass, + formatDownloadTotal, resolveDownloadSizeDisplay } from '../utils/downloadProgress'; @@ -74,7 +75,11 @@ export const DownloadItem = React.memo(({ totalIsEstimate: liveProgress?.total_is_estimate ?? download.totalIsEstimate, fallbackSize: download.size }); - const hasDownloadedAmount = Boolean(sizeDisplay.downloaded && sizeDisplay.total); + const hasDownloadedAmount = download.status !== 'completed' && + Boolean(sizeDisplay.downloaded && sizeDisplay.total); + const completedSizeLabel = download.status === 'completed' + ? formatDownloadTotal(sizeDisplay) + : sizeDisplay.fallback; return (
(({ className="tabular-nums" title={hasDownloadedAmount ? `${sizeDisplay.downloaded} downloaded of ${sizeDisplay.totalIsEstimate ? '~' : ''}${sizeDisplay.total} ${sizeDisplay.unit}` - : sizeDisplay.fallback} + : completedSizeLabel} aria-label={hasDownloadedAmount ? `${sizeDisplay.downloaded} downloaded of ${sizeDisplay.totalIsEstimate ? 'approximately ' : ''}${sizeDisplay.total} ${sizeDisplay.unit}` - : sizeDisplay.fallback} + : completedSizeLabel} > {hasDownloadedAmount ? ( <> @@ -113,7 +118,7 @@ export const DownloadItem = React.memo(({ {sizeDisplay.totalIsEstimate ? '~' : ''}{sizeDisplay.total} {sizeDisplay.unit} - ) : sizeDisplay.fallback} + ) : completedSizeLabel}
diff --git a/src/components/PropertiesModal.tsx b/src/components/PropertiesModal.tsx index 6682c76..3d04424 100644 --- a/src/components/PropertiesModal.tsx +++ b/src/components/PropertiesModal.tsx @@ -12,6 +12,7 @@ import { } from '../utils/downloadActions'; import { downloadProgressColorClass, + formatDownloadTotal, resolveDownloadSizeDisplay } from '../utils/downloadProgress'; @@ -195,7 +196,11 @@ export const PropertiesModal = () => { totalIsEstimate: liveProgress?.total_is_estimate ?? item.totalIsEstimate, fallbackSize: item.size }); - const hasDownloadedAmount = Boolean(sizeDisplay.downloaded && sizeDisplay.total); + const hasDownloadedAmount = item.status !== 'completed' && + Boolean(sizeDisplay.downloaded && sizeDisplay.total); + const completedSizeLabel = item.status === 'completed' + ? formatDownloadTotal(sizeDisplay) + : sizeDisplay.fallback; let statusColor = 'text-text-secondary'; let StatusIcon = Info; @@ -238,7 +243,7 @@ export const PropertiesModal = () => { className="truncate" title={hasDownloadedAmount ? `${sizeDisplay.downloaded} downloaded of ${sizeDisplay.totalIsEstimate ? 'approximately ' : ''}${sizeDisplay.total} ${sizeDisplay.unit}` - : sizeDisplay.fallback} + : completedSizeLabel} > {hasDownloadedAmount ? ( <> @@ -248,7 +253,7 @@ export const PropertiesModal = () => { {sizeDisplay.totalIsEstimate ? '~' : ''}{sizeDisplay.total} {sizeDisplay.unit} - ) : sizeDisplay.fallback} + ) : completedSizeLabel}
Speed{displayedSpeed}
diff --git a/src/utils/downloadProgress.test.ts b/src/utils/downloadProgress.test.ts index a6f8a44..f691cd4 100644 --- a/src/utils/downloadProgress.test.ts +++ b/src/utils/downloadProgress.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { formatDownloadBytes, resolveDownloadSizeDisplay } from './downloadProgress'; +import { formatDownloadBytes, formatDownloadTotal, resolveDownloadSizeDisplay } from './downloadProgress'; describe('download progress size display', () => { it('formats byte counts using the binary units used by the download engines', () => { @@ -33,4 +33,14 @@ describe('download progress size display', () => { unit: 'GB' }); }); + + it('formats a completed download using only its total size', () => { + const display = resolveDownloadSizeDisplay({ + downloadedBytes: 1.2 * 1024 ** 3, + totalBytes: 2.4 * 1024 ** 3, + fallbackSize: '2.4 GB' + }); + + expect(formatDownloadTotal(display)).toBe('2.40 GB'); + }); }); diff --git a/src/utils/downloadProgress.ts b/src/utils/downloadProgress.ts index 31baa4b..b3f47c3 100644 --- a/src/utils/downloadProgress.ts +++ b/src/utils/downloadProgress.ts @@ -34,6 +34,11 @@ export const formatDownloadBytes = (bytes: number): string => { return `${formatDownloadBytesInUnit(bytes, unitIndex)} ${BYTE_UNITS[unitIndex]}`; }; +export const formatDownloadTotal = (display: DownloadSizeDisplay): string => + display.total && display.unit + ? `${display.totalIsEstimate ? '~' : ''}${display.total} ${display.unit}` + : display.fallback; + export const resolveDownloadSizeDisplay = ({ downloadedBytes, totalBytes,