Skip to content

Commit

Permalink
Merge pull request SubtitleEdit#8397 from ivandrofly/feature/report-p…
Browse files Browse the repository at this point in the history
…rogress

Refactor progress report in WhisperModelDownload
  • Loading branch information
niksedk committed Jun 5, 2024
2 parents 24de4b2 + 8179cee commit e963cfd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/ui/Forms/AudioToText/WhisperModelDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ private void MultiFileDownload()
}
}

var progressReport = new Progress<float>((progress) =>
{
var pct = (int)Math.Round(progress * 100.0, MidpointRounding.AwayFromZero);
labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait + " " + pct + "%";
});
foreach (var url in LastDownloadedModel.Urls)
{
using (var httpClient = DownloaderFactory.MakeHttpClient())
Expand All @@ -112,11 +117,8 @@ private void MultiFileDownload()
labelFileName.Text = url.Split('/').Last();
using (var downloadStream = new FileStream(_downloadFileName, FileMode.Create, FileAccess.Write))
{
var downloadTask = httpClient.DownloadAsync(url, downloadStream, new Progress<float>((progress) =>
{
var pct = (int)Math.Round(progress * 100.0, MidpointRounding.AwayFromZero);
labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait + " " + pct + "%";
}), _cancellationTokenSource.Token);
var downloadTask = httpClient.DownloadAsync(url, downloadStream, progressReport,
_cancellationTokenSource.Token);

while (!downloadTask.IsCompleted && !downloadTask.IsCanceled)
{
Expand Down

0 comments on commit e963cfd

Please sign in to comment.