feat: 优化下载速度显示 (#11541)

* feat: 优化下载速度显示

下载速度超过1MiB/s时以MiB/s为单位显示下载速度

* feat: apply review

* style: format

---------

Co-authored-by: status102 <102887808+status102@users.noreply.github.com>
This commit is contained in:
502y
2025-01-14 20:32:17 +08:00
committed by GitHub
parent 3fa01d304c
commit 7afa244e6a

View File

@@ -882,8 +882,21 @@ public class VersionUpdateViewModel : Screen
public static void OutputDownloadProgress(long value = 0, long maximum = 1, int len = 0, double ts = 1)
{
OutputDownloadProgress(
$"[{value / 1048576.0:F}MiB/{maximum / 1048576.0:F}MiB({100 * value / maximum}%) {len / ts / 1024.0:F} KiB/s]");
string progress = $"[{value / 1048576.0:F}MiB/{maximum / 1048576.0:F}MiB ({value * 100.0 / maximum:F}%)";
double speedInKiBPerSecond = len / ts / 1024.0;
string speedDisplay;
if (speedInKiBPerSecond >= 1024)
{
speedDisplay = $"{speedInKiBPerSecond / 1024.0:F} MiB/s";
}
else
{
speedDisplay = $"{speedInKiBPerSecond:F} KiB/s";
}
OutputDownloadProgress(progress + $" {speedDisplay}");
}
private static void OutputDownloadProgress(string output, bool downloading = true)