You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.8 KiB
58 lines
1.8 KiB
1 year ago
|
using StabilityMatrix.Avalonia.ViewModels.Base;
|
||
1 year ago
|
using StabilityMatrix.Core.Helper;
|
||
|
using StabilityMatrix.Core.Models.Progress;
|
||
|
|
||
1 year ago
|
namespace StabilityMatrix.Avalonia.ViewModels.Progress;
|
||
1 year ago
|
|
||
1 year ago
|
public class ProgressItemViewModel : ProgressItemViewModelBase
|
||
1 year ago
|
{
|
||
|
public ProgressItemViewModel(ProgressItem progressItem)
|
||
|
{
|
||
|
Id = progressItem.ProgressId;
|
||
|
Name = progressItem.Name;
|
||
1 year ago
|
Progress.Value = progressItem.Progress.Percentage;
|
||
1 year ago
|
Failed = progressItem.Failed;
|
||
1 year ago
|
Progress.Text = GetProgressText(progressItem.Progress);
|
||
1 year ago
|
Progress.IsIndeterminate = progressItem.Progress.IsIndeterminate;
|
||
1 year ago
|
|
||
|
EventManager.Instance.ProgressChanged += OnProgressChanged;
|
||
|
}
|
||
|
|
||
|
private void OnProgressChanged(object? sender, ProgressItem e)
|
||
|
{
|
||
|
if (e.ProgressId != Id)
|
||
|
return;
|
||
|
|
||
1 year ago
|
Progress.Value = e.Progress.Percentage;
|
||
1 year ago
|
Failed = e.Failed;
|
||
1 year ago
|
Progress.Text = GetProgressText(e.Progress);
|
||
1 year ago
|
Progress.IsIndeterminate = e.Progress.IsIndeterminate;
|
||
1 year ago
|
}
|
||
|
|
||
|
private string GetProgressText(ProgressReport report)
|
||
|
{
|
||
|
switch (report.Type)
|
||
|
{
|
||
|
case ProgressType.Generic:
|
||
|
break;
|
||
|
case ProgressType.Download:
|
||
|
return Failed ? "Download Failed" : "Downloading...";
|
||
|
case ProgressType.Extract:
|
||
|
return Failed ? "Extraction Failed" : "Extracting...";
|
||
1 year ago
|
case ProgressType.Update:
|
||
|
return Failed ? "Update Failed" : "Updating...";
|
||
1 year ago
|
}
|
||
|
|
||
|
if (Failed)
|
||
|
{
|
||
|
return "Failed";
|
||
|
}
|
||
|
|
||
|
return string.IsNullOrWhiteSpace(report.Message)
|
||
|
? string.IsNullOrWhiteSpace(report.Title)
|
||
|
? string.Empty
|
||
|
: report.Title
|
||
|
: report.Message;
|
||
|
}
|
||
|
}
|