-
Notifications
You must be signed in to change notification settings - Fork 808
Expand file tree
/
Copy pathOperationOutputViewModel.cs
More file actions
40 lines (33 loc) · 1.41 KB
/
OperationOutputViewModel.cs
File metadata and controls
40 lines (33 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections.ObjectModel;
using Avalonia.Media;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using UniGetUI.Avalonia.ViewModels.Pages.LogPages;
using UniGetUI.PackageOperations;
namespace UniGetUI.Avalonia.ViewModels.DialogPages;
public partial class OperationOutputViewModel : ObservableObject
{
[ObservableProperty] private string _title = "";
public ObservableCollection<LogLineItem> OutputLines { get; } = new();
private static readonly IBrush _errorBrush = new SolidColorBrush(Color.Parse("#FF6B6B"));
private static readonly IBrush _debugBrush = new SolidColorBrush(Color.Parse("#888888"));
private static readonly IBrush _normalBrush = Brushes.White;
public OperationOutputViewModel(AbstractOperation operation)
{
Title = operation.Metadata.Title;
foreach (var (text, type) in operation.GetOutput())
OutputLines.Add(MakeLine(text, type));
operation.LogLineAdded += (_, ev) =>
Dispatcher.UIThread.Post(() => OutputLines.Add(MakeLine(ev.Item1, ev.Item2)));
}
private LogLineItem MakeLine(string text, AbstractOperation.LineType type)
{
IBrush brush = type switch
{
AbstractOperation.LineType.Error => _errorBrush,
AbstractOperation.LineType.VerboseDetails => _debugBrush,
_ => _normalBrush,
};
return new LogLineItem(text, brush);
}
}