Merge pull request #749 from bluepilledgreat/feature/smooth-progress-bar

Smoother progress bar
This commit is contained in:
pizzaboxer 2023-10-10 22:12:45 +01:00 committed by GitHub
commit b1429fa588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 80 additions and 10 deletions

View File

@ -10,6 +10,8 @@ namespace Bloxstrap
public class Bootstrapper
{
#region Properties
private const int ProgressBarMaximum = 10000;
// in case a new package is added, you can find the corresponding directory
// by opening the stock bootstrapper in a hex editor
// TODO - there ideally should be a less static way to do this that's not hardcoded?
@ -91,15 +93,16 @@ namespace Bloxstrap
private void UpdateProgressBar()
{
int newProgress = (int)Math.Floor(_progressIncrement * _totalDownloadedBytes);
if (Dialog is null)
return;
int progressValue = (int)Math.Floor(_progressIncrement * _totalDownloadedBytes);
// bugcheck: if we're restoring a file from a package, it'll incorrectly increment the progress beyond 100
// too lazy to fix properly so lol
if (newProgress > 100)
return;
progressValue = Math.Clamp(progressValue, 0, ProgressBarMaximum);
if (Dialog is not null)
Dialog.ProgressValue = newProgress;
Dialog.ProgressValue = progressValue;
}
public async Task Run()
@ -806,10 +809,12 @@ namespace Bloxstrap
{
Dialog.CancelEnabled = true;
Dialog.ProgressStyle = ProgressBarStyle.Continuous;
}
// compute total bytes to download
_progressIncrement = (double)100 / _versionPackageManifest.Sum(package => package.PackedSize);
Dialog.ProgressMaximum = ProgressBarMaximum;
// compute total bytes to download
_progressIncrement = (double)ProgressBarMaximum / _versionPackageManifest.Sum(package => package.PackedSize);
}
foreach (Package package in _versionPackageManifest)
{

View File

@ -14,6 +14,7 @@ namespace Bloxstrap.UI.Elements.Bootstrapper.Base
protected virtual string _message { get; set; } = "Please wait...";
protected virtual ProgressBarStyle _progressStyle { get; set; }
protected virtual int _progressValue { get; set; }
protected virtual int _progressMaximum { get; set; }
protected virtual bool _cancelEnabled { get; set; }
public string Message
@ -40,6 +41,18 @@ namespace Bloxstrap.UI.Elements.Bootstrapper.Base
}
}
public int ProgressMaximum
{
get => _progressMaximum;
set
{
if (InvokeRequired)
Invoke(() => _progressMaximum = value);
else
_progressMaximum = value;
}
}
public int ProgressValue
{
get => _progressValue;

View File

@ -38,7 +38,7 @@
<ScaleTransform ScaleY="0.9"/>
</TextBlock.LayoutTransform>
</TextBlock>
<ProgressBar Grid.Row="1" Width="480" Height="12" Foreground="{Binding Foreground}" Background="{Binding ProgressBarBackground}" BorderThickness="0" IsIndeterminate="{Binding ProgressIndeterminate}" Value="{Binding ProgressValue}"></ProgressBar>
<ProgressBar Grid.Row="1" Width="480" Height="12" Foreground="{Binding Foreground}" Background="{Binding ProgressBarBackground}" BorderThickness="0" IsIndeterminate="{Binding ProgressIndeterminate}" Maximum="{Binding ProgressMaximum, Mode=OneWay}" Value="{Binding ProgressValue}"></ProgressBar>
</Grid>
</Grid>
</Border>

View File

@ -41,6 +41,16 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
}
}
public int ProgressMaximum
{
get => _viewModel.ProgressMaximum;
set
{
_viewModel.ProgressMaximum = value;
_viewModel.OnPropertyChanged(nameof(_viewModel.ProgressMaximum));
}
}
public int ProgressValue
{
get => _viewModel.ProgressValue;

View File

@ -36,7 +36,7 @@
</Border>
<StackPanel Grid.Column="1">
<TextBlock Margin="16,8,0,0" FontSize="20" Text="{Binding Message, Mode=OneWay}" Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
<ProgressBar Margin="16,16,0,16" IsIndeterminate="{Binding ProgressIndeterminate, Mode=OneWay}" Value="{Binding ProgressValue, Mode=OneWay}" />
<ProgressBar Margin="16,16,0,16" IsIndeterminate="{Binding ProgressIndeterminate, Mode=OneWay}" Maximum="{Binding ProgressMaximum, Mode=OneWay}" Value="{Binding ProgressValue, Mode=OneWay}" />
</StackPanel>
</Grid>

View File

@ -42,6 +42,16 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
}
}
public int ProgressMaximum
{
get => _viewModel.ProgressMaximum;
set
{
_viewModel.ProgressMaximum = value;
_viewModel.OnPropertyChanged(nameof(_viewModel.ProgressMaximum));
}
}
public int ProgressValue
{
get => _viewModel.ProgressValue;

View File

@ -21,6 +21,12 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
set => ProgressBar.Style = value;
}
protected override int _progressMaximum
{
get => ProgressBar.Maximum;
set => ProgressBar.Maximum = value;
}
protected override int _progressValue
{
get => ProgressBar.Value;

View File

@ -20,6 +20,12 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
set => ProgressBar.Style = value;
}
protected override int _progressMaximum
{
get => ProgressBar.Maximum;
set => ProgressBar.Maximum = value;
}
protected override int _progressValue
{
get => ProgressBar.Value;

View File

@ -21,6 +21,12 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
set => ProgressBar.Style = value;
}
protected override int _progressMaximum
{
get => ProgressBar.Maximum;
set => ProgressBar.Maximum = value;
}
protected override int _progressValue
{
get => ProgressBar.Value;

View File

@ -37,6 +37,18 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
}
}
protected sealed override int _progressMaximum
{
get => _dialogPage.ProgressBar?.Maximum ?? 0;
set
{
if (_dialogPage.ProgressBar is null)
return;
_dialogPage.ProgressBar.Maximum = value;
}
}
protected sealed override int _progressValue
{
get => _dialogPage.ProgressBar?.Value ?? 0;

View File

@ -9,6 +9,7 @@ namespace Bloxstrap.UI
string Message { get; set; }
ProgressBarStyle ProgressStyle { get; set; }
int ProgressValue { get; set; }
int ProgressMaximum { get; set; }
bool CancelEnabled { get; set; }
void ShowBootstrapper();

View File

@ -16,6 +16,7 @@ namespace Bloxstrap.UI.ViewModels.Bootstrapper
public ImageSource Icon { get; set; } = App.Settings.Prop.BootstrapperIcon.GetIcon().GetImageSource();
public string Message { get; set; } = "Please wait...";
public bool ProgressIndeterminate { get; set; } = true;
public int ProgressMaximum { get; set; } = 0;
public int ProgressValue { get; set; } = 0;
public bool CancelEnabled { get; set; } = false;