From d821c824de70b537d78bac4f9567b81673f53e0e Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Tue, 13 Jan 2026 18:05:06 +0800 Subject: feat: enhance DownloadMonitor with improved event handling and UI updates --- ui/src/lib/DownloadMonitor.svelte | 68 ++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 29 deletions(-) (limited to 'ui/src/lib') diff --git a/ui/src/lib/DownloadMonitor.svelte b/ui/src/lib/DownloadMonitor.svelte index b2751fe..b796591 100644 --- a/ui/src/lib/DownloadMonitor.svelte +++ b/ui/src/lib/DownloadMonitor.svelte @@ -23,33 +23,38 @@ onMount(async () => { unlistenStart = await listen("download-start", (event) => { - visible = true; - totalFiles = event.payload; - progress = 0; - statusText = "Starting download..."; - currentFile = ""; + visible = true; + totalFiles = event.payload; + progress = 0; + statusText = "Starting download..."; + currentFile = ""; }); - unlistenProgress = await listen("download-progress", (event) => { + unlistenProgress = await listen( + "download-progress", + (event) => { const payload = event.payload; currentFile = payload.file; - + // Simple file progress for now. Global progress would require tracking all files. // For single file (Client jar), this is accurate. downloadedBytes = payload.downloaded; totalBytes = payload.total; - + statusText = payload.status; - + if (payload.total > 0) { - progress = (payload.downloaded / payload.total) * 100; + progress = (payload.downloaded / payload.total) * 100; } - }); + } + ); unlistenComplete = await listen("download-complete", () => { - statusText = "Done!"; - progress = 100; - setTimeout(() => { visible = false; }, 2000); + statusText = "Done!"; + progress = 100; + setTimeout(() => { + visible = false; + }, 2000); }); }); @@ -58,35 +63,40 @@ if (unlistenStart) unlistenStart(); if (unlistenComplete) unlistenComplete(); }); - + function formatBytes(bytes: number) { - if (bytes === 0) return '0 B'; - const k = 1024; - const sizes = ['B', 'KB', 'MB', 'GB']; - const i = Math.floor(Math.log(bytes) / Math.log(k)); - return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; + if (bytes === 0) return "0 B"; + const k = 1024; + const sizes = ["B", "KB", "MB", "GB"]; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i]; } {#if visible} -
+
-

Downloads

- {statusText} +

Downloads

+ {statusText}
- +
- {currentFile || "Waiting..."} + {currentFile || "Waiting..."}
-
+
- {formatBytes(downloadedBytes)} / {formatBytes(totalBytes)} - {Math.round(progress)}% + {formatBytes(downloadedBytes)} / {formatBytes(totalBytes)} + {Math.round(progress)}%
-
+
{/if} -- cgit v1.2.3-70-g09d2