From 6677e22ab69e3e66e3f8ce65a156744a3f679b5b Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Wed, 5 Nov 2025 11:52:04 -0700 Subject: [PATCH] Improvements to download menu --- src-tauri/src/lib.rs | 6 +++--- src/app/componets/ProgressBar.tsx | 17 +++++++++++++++ src/app/layout.tsx | 36 +++++++++++++++++++++++++------ src/app/types/DownloadProgress.ts | 1 + 4 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 src/app/componets/ProgressBar.tsx diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d0201aa..477e05c 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -150,12 +150,12 @@ async fn download( downloaded += chunk.len() as u64; let progress = if total_size > 0 { - (downloaded * 100 / total_size) as u8 + (downloaded as f64 / total_size as f64) * 100.0 } else { - 0 + 0.0 }; - app.emit("download-progress", format!("{}:{}", &name, progress)) + app.emit("download-progress", format!("{}:{:.8}:{}", &name, progress, downloaded)) .unwrap(); } diff --git a/src/app/componets/ProgressBar.tsx b/src/app/componets/ProgressBar.tsx new file mode 100644 index 0000000..e5f5a2a --- /dev/null +++ b/src/app/componets/ProgressBar.tsx @@ -0,0 +1,17 @@ +type ProgressBarProps = { + progress: number + className?: string +} + +export default function ProgressBar ({ progress, className }: ProgressBarProps) { + return ( +
+
+
+ ) +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 80662ac..524c347 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -42,6 +42,8 @@ import { listen } from '@tauri-apps/api/event' import { usePathname } from 'next/navigation' import { arch, platform } from '@tauri-apps/plugin-os' import VersionInfo from './componets/VersionInfo' +import prettyBytes from 'pretty-bytes' +import ProgressBar from './componets/ProgressBar' const roboto = Roboto({ subsets: ['latin'] @@ -113,13 +115,14 @@ export default function RootLayout ({ let unlistenUninstalled: (() => void) | null = null listen('download-progress', event => { - const [versionName, progStr] = event.payload.split(':') + const [versionName, progStr, totalSizeStr] = event.payload.split(':') const prog = Number(progStr) + const progBytes = Number(totalSizeStr) setDownloadProgress(prev => { const i = prev.findIndex(d => d.version === versionName) if (i === -1) return prev const copy = [...prev] - copy[i] = { ...copy[i], progress: prog } + copy[i] = { ...copy[i], progress: prog, progressBytes: progBytes } return copy }) }).then(f => (unlistenProgress = f)) @@ -268,7 +271,7 @@ export default function RootLayout ({ setSelectedVersionList([]) const newDownloads = list.map( - version => new DownloadProgress(version, 0, false, true, false, false) + version => new DownloadProgress(version, 0, 0, false, true, false, false) ) setDownloadProgress(newDownloads) @@ -655,9 +658,30 @@ export default function RootLayout ({ Finishing... ) : ( - - Downloading: {v.progress}% done - +
+ + Downloading: {Math.floor(v.progress)}% + of ( + {prettyBytes(v.progressBytes, { + minimumFractionDigits: 1, + maximumFractionDigits: 1 + })} + / + {prettyBytes( + getVersionInfo(v.version)?.size ?? + 0, + { + minimumFractionDigits: 1, + maximumFractionDigits: 1 + } + )} + ) + + +
)}
diff --git a/src/app/types/DownloadProgress.ts b/src/app/types/DownloadProgress.ts index 98644cd..959eb8a 100644 --- a/src/app/types/DownloadProgress.ts +++ b/src/app/types/DownloadProgress.ts @@ -2,6 +2,7 @@ export class DownloadProgress { constructor( public version: string, public progress: number, + public progressBytes: number, public failed: boolean, public queued: boolean, public hash_checking: boolean,