diff --git a/src/Views/PopupRunningStatus.axaml b/src/Views/PopupRunningStatus.axaml index 6a0dbdb42..a0412cba7 100644 --- a/src/Views/PopupRunningStatus.axaml +++ b/src/Views/PopupRunningStatus.axaml @@ -21,10 +21,21 @@ FontStyle="Italic" Text="{Binding #ThisControl.Description}"/> - + + + + + diff --git a/src/Views/PopupRunningStatus.axaml.cs b/src/Views/PopupRunningStatus.axaml.cs index 72caaed86..8016191e8 100644 --- a/src/Views/PopupRunningStatus.axaml.cs +++ b/src/Views/PopupRunningStatus.axaml.cs @@ -1,3 +1,4 @@ +using System.Text.RegularExpressions; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Shapes; @@ -50,12 +51,17 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang else StopAnim(); } + else if (change.Property == DescriptionProperty) + { + if (IsVisible && !_isUnloading) + UpdateProgress(); + } } private void StartAnim() { Icon.Content = new Path() { Classes = { "waiting" } }; - ProgressBar.IsIndeterminate = true; + UpdateProgress(); } private void StopAnim() @@ -64,9 +70,33 @@ private void StopAnim() path.Classes.Clear(); Icon.Content = null; ProgressBar.IsIndeterminate = false; + ProgressBar.Value = 0; + Percentage.IsVisible = false; + } + + private void UpdateProgress() + { + // Git reports the progress of long-running operations as `: NN% (...)`. Only the + // percentage is used here, so it also works with translated phase names. + var match = string.IsNullOrEmpty(_description) ? null : REG_PROGRESS().Match(_description); + if (match is { Success: true } && int.TryParse(match.Groups[1].Value, out var percent) && percent <= 100) + { + ProgressBar.IsIndeterminate = false; + ProgressBar.Value = percent; + Percentage.Text = $"{percent}%"; + Percentage.IsVisible = true; + } + else + { + ProgressBar.IsIndeterminate = true; + Percentage.IsVisible = false; + } } private string _description = string.Empty; private bool _isUnloading = false; + + [GeneratedRegex(@"^[^%]+?:\s+(\d{1,3})%")] + private static partial Regex REG_PROGRESS(); } }