Skip to content

Commit

Permalink
Corrected auto updater.
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszCichecki committed Aug 16, 2022
1 parent be911bf commit 35a2474
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions LenovoLegionToolkit.WPF/Windows/Utils/UpdateWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,14 @@
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using LenovoLegionToolkit.Lib;
using LenovoLegionToolkit.Lib.Utils;
using LenovoLegionToolkit.WPF.Extensions;

namespace LenovoLegionToolkit.WPF.Windows.Utils
{
public partial class UpdateWindow
public partial class UpdateWindow : IProgress<float>
{
private class DownloadProgress : IProgress<float>
{
private readonly ProgressBar _progressBar;

public DownloadProgress(ProgressBar progressBar)
{
_progressBar = progressBar;
}

public void Report(float value)
{
_progressBar.IsIndeterminate = !(value > 0);
_progressBar.Value = value;
}
}

private readonly UpdateChecker _updateChecker = IoCContainer.Resolve<UpdateChecker>();

private CancellationTokenSource? _downloadCancellationTokenSource;
Expand Down Expand Up @@ -80,7 +63,7 @@ private async void DownloadButton_Click(object sender, RoutedEventArgs e)

SetDownloading(true);

var path = await _updateChecker.DownloadLatestUpdate(new DownloadProgress(_downloadProgressBar), _downloadCancellationTokenSource.Token);
var path = await _updateChecker.DownloadLatestUpdate(this, _downloadCancellationTokenSource.Token);

_downloadCancellationTokenSource = null;

Expand Down Expand Up @@ -127,5 +110,11 @@ private void SetDownloading(bool isDownloading)
_cancelDownloadButton.IsEnabled = false;
}
}

public void Report(float value) => Dispatcher.Invoke(() =>
{
_downloadProgressBar.IsIndeterminate = !(value > 0);
_downloadProgressBar.Value = value;
});
}
}

0 comments on commit 35a2474

Please sign in to comment.