aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/lib/DownloadMonitor.svelte
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2026-01-13 18:05:06 +0800
committerHsiangNianian <i@jyunko.cn>2026-01-13 18:05:06 +0800
commitd821c824de70b537d78bac4f9567b81673f53e0e (patch)
tree0a67ac76f006bab727513005cf2b52feb572af40 /ui/src/lib/DownloadMonitor.svelte
parent293f7a73095b5210a812725172041bad531484fe (diff)
downloadDropOut-d821c824de70b537d78bac4f9567b81673f53e0e.tar.gz
DropOut-d821c824de70b537d78bac4f9567b81673f53e0e.zip
feat: enhance DownloadMonitor with improved event handling and UI updates
Diffstat (limited to 'ui/src/lib/DownloadMonitor.svelte')
-rw-r--r--ui/src/lib/DownloadMonitor.svelte68
1 files changed, 39 insertions, 29 deletions
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<number>("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<DownloadEvent>("download-progress", (event) => {
+ unlistenProgress = await listen<DownloadEvent>(
+ "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];
}
</script>
{#if visible}
-<div class="fixed bottom-28 right-8 z-50 w-80 bg-zinc-900/90 backdrop-blur-md border border-zinc-700 rounded-lg shadow-2xl p-4 animate-in slide-in-from-right-10 fade-in duration-300">
+ <div
+ class="fixed bottom-28 right-8 z-50 w-80 bg-zinc-900/90 backdrop-blur-md border border-zinc-700 rounded-lg shadow-2xl p-4 animate-in slide-in-from-right-10 fade-in duration-300"
+ >
<div class="flex items-center justify-between mb-2">
- <h3 class="text-white font-bold text-sm">Downloads</h3>
- <span class="text-xs text-zinc-400">{statusText}</span>
+ <h3 class="text-white font-bold text-sm">Downloads</h3>
+ <span class="text-xs text-zinc-400">{statusText}</span>
</div>
-
+
<div class="text-xs text-zinc-300 truncate mb-1" title={currentFile}>
- {currentFile || "Waiting..."}
+ {currentFile || "Waiting..."}
</div>
<!-- Progress Bar -->
<div class="w-full bg-zinc-800 rounded-full h-2 mb-2 overflow-hidden">
- <div class="bg-gradient-to-r from-green-500 to-emerald-400 h-2 rounded-full transition-all duration-200" style="width: {progress}%"></div>
+ <div
+ class="bg-gradient-to-r from-green-500 to-emerald-400 h-2 rounded-full transition-all duration-200"
+ style="width: {progress}%"
+ ></div>
</div>
<div class="flex justify-between text-[10px] text-zinc-500 font-mono">
- <span>{formatBytes(downloadedBytes)} / {formatBytes(totalBytes)}</span>
- <span>{Math.round(progress)}%</span>
+ <span>{formatBytes(downloadedBytes)} / {formatBytes(totalBytes)}</span>
+ <span>{Math.round(progress)}%</span>
</div>
-</div>
+ </div>
{/if}