Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/Views/PopupRunningStatus.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,21 @@
FontStyle="Italic"
Text="{Binding #ThisControl.Description}"/>

<ProgressBar x:Name="ProgressBar"
Margin="0,8,0,0"
HorizontalAlignment="Stretch"
Background="{DynamicResource Brush.FG2}" Foreground="{DynamicResource Brush.Accent}"
Minimum="0" Maximum="100"/>
<Grid Margin="0,8,0,0" ColumnDefinitions="*,Auto">
<ProgressBar Grid.Column="0"
x:Name="ProgressBar"
HorizontalAlignment="Stretch"
Background="{DynamicResource Brush.FG2}" Foreground="{DynamicResource Brush.Accent}"
Minimum="0" Maximum="100"/>

<TextBlock Grid.Column="1"
x:Name="Percentage"
Margin="8,0,0,0"
MinWidth="32"
TextAlignment="Right"
VerticalAlignment="Center"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
IsVisible="False"/>
</Grid>
</StackPanel>
</UserControl>
32 changes: 31 additions & 1 deletion src/Views/PopupRunningStatus.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.RegularExpressions;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
Expand Down Expand Up @@ -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()
Expand All @@ -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 `<phase>: 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();
}
}