Skip to content

Commit db09fde

Browse files
committed
feat: add DownloadCompleted event.
1 parent 5855bd1 commit db09fde

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/Client.Avalonia/Services/IDownloadService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public interface IDownloadService
88
{
99
event Action<DownloadStatistics> ProgressChanged;
1010
event Action<DownloadStatus> StatusChanged;
11+
event Action DownloadCompleted;
1112

1213
DownloadStatistics CurrentStatistics { get; }
1314
DownloadStatus Status { get; }

src/Client.Avalonia/Services/MockDownloadService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class MockDownloadService : IDownloadService
88
{
99
public event Action<DownloadStatistics>? ProgressChanged;
1010
public event Action<DownloadStatus>? StatusChanged;
11+
public event Action? DownloadCompleted;
1112

1213
private readonly DispatcherTimer _timer;
1314
private readonly Random _random;
@@ -93,6 +94,7 @@ private void UpdateProgress(object? sender, EventArgs e)
9394
{
9495
_timer.Stop();
9596
UpdateStatus(DownloadStatus.Completed);
97+
DownloadCompleted?.Invoke();
9698
}
9799
}
98100

src/Client.Avalonia/ViewModels/MainViewViewModel.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public MainViewViewModel(IDownloadService downloadService)
2626

2727
_downloadService.ProgressChanged += stats => Statistics = stats;
2828
_downloadService.StatusChanged += status => Status = status;
29-
_downloadService.StatusChanged += OnDownloadCompleted;
29+
_downloadService.DownloadCompleted += OnDownloadCompleted;
3030

3131
Statistics = _downloadService.CurrentStatistics;
3232
Status = _downloadService.Status;
@@ -49,9 +49,8 @@ public MainViewViewModel(IDownloadService downloadService)
4949

5050
#endregion
5151

52-
private void OnDownloadCompleted(DownloadStatus status)
52+
private void OnDownloadCompleted()
5353
{
54-
if (status is not DownloadStatus.Completed) return;
5554
_notificationManager.Show(new Notification(
5655
"更新完成",
5756
$"已更新到最新版本,版本号:{Statistics.Version}",

0 commit comments

Comments
 (0)