mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge branch 'development' into feature/workshop
This commit is contained in:
commit
89a910d9e2
@ -5,6 +5,7 @@ using Artemis.UI.Screens.Debugger.DataModel;
|
|||||||
using Artemis.UI.Screens.Debugger.Logs;
|
using Artemis.UI.Screens.Debugger.Logs;
|
||||||
using Artemis.UI.Screens.Debugger.Performance;
|
using Artemis.UI.Screens.Debugger.Performance;
|
||||||
using Artemis.UI.Screens.Debugger.Render;
|
using Artemis.UI.Screens.Debugger.Render;
|
||||||
|
using Artemis.UI.Screens.Debugger.Routing;
|
||||||
using Artemis.UI.Services.Interfaces;
|
using Artemis.UI.Services.Interfaces;
|
||||||
using Artemis.UI.Shared;
|
using Artemis.UI.Shared;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
@ -15,9 +16,9 @@ public class DebugViewModel : ActivatableViewModelBase, IScreen
|
|||||||
{
|
{
|
||||||
private ViewModelBase _selectedItem;
|
private ViewModelBase _selectedItem;
|
||||||
|
|
||||||
public DebugViewModel(IDebugService debugService, RenderDebugViewModel render, DataModelDebugViewModel dataModel, PerformanceDebugViewModel performance, LogsDebugViewModel logs)
|
public DebugViewModel(IDebugService debugService, RenderDebugViewModel render, DataModelDebugViewModel dataModel, PerformanceDebugViewModel performance, RoutingDebugViewModel routing, LogsDebugViewModel logs)
|
||||||
{
|
{
|
||||||
Items = new ObservableCollection<ViewModelBase> {render, dataModel, performance, logs};
|
Items = new ObservableCollection<ViewModelBase> {render, dataModel, performance, routing, logs};
|
||||||
_selectedItem = render;
|
_selectedItem = render;
|
||||||
|
|
||||||
this.WhenActivated(d => Disposable.Create(debugService.ClearDebugger).DisposeWith(d));
|
this.WhenActivated(d => Disposable.Create(debugService.ClearDebugger).DisposeWith(d));
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:routing="clr-namespace:Artemis.UI.Screens.Debugger.Routing"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="Artemis.UI.Screens.Debugger.Routing.RoutingDebugView"
|
||||||
|
x:DataType="routing:RoutingDebugViewModel">
|
||||||
|
|
||||||
|
<Grid RowDefinitions="Auto,Auto,*" ColumnDefinitions="*,Auto">
|
||||||
|
<TextBox Grid.Row="0" Grid.Column="0" Watermark="Enter a route to navigate to" Text="{CompiledBinding Route}">
|
||||||
|
<TextBox.KeyBindings>
|
||||||
|
<KeyBinding Gesture="Enter" Command="{CompiledBinding Navigate}"></KeyBinding>
|
||||||
|
</TextBox.KeyBindings>
|
||||||
|
</TextBox>
|
||||||
|
<Button Grid.Row="0" Grid.Column="1" Margin="5 0 0 0" Command="{CompiledBinding Navigate}">Navigate</Button>
|
||||||
|
|
||||||
|
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="0 15">Navigation logs</TextBlock>
|
||||||
|
<ScrollViewer Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Name="LogsScrollViewer" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
|
||||||
|
<SelectableTextBlock
|
||||||
|
Inlines="{CompiledBinding Lines}"
|
||||||
|
FontFamily="Consolas"
|
||||||
|
SizeChanged="Control_OnSizeChanged"
|
||||||
|
SelectionBrush="{StaticResource TextControlSelectionHighlightColor}" />
|
||||||
|
</ScrollViewer>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</UserControl>
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.ReactiveUI;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Screens.Debugger.Routing;
|
||||||
|
|
||||||
|
public partial class RoutingDebugView : ReactiveUserControl<RoutingDebugViewModel>
|
||||||
|
{
|
||||||
|
public RoutingDebugView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
base.OnInitialized();
|
||||||
|
Dispatcher.UIThread.Post(() => LogsScrollViewer.ScrollToEnd(), DispatcherPriority.ApplicationIdle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Control_OnSizeChanged(object? sender, SizeChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (!(LogsScrollViewer.Extent.Height - LogsScrollViewer.Offset.Y - LogsScrollViewer.Bounds.Bottom <= 60))
|
||||||
|
return;
|
||||||
|
Dispatcher.UIThread.Post(() => LogsScrollViewer.ScrollToEnd(), DispatcherPriority.Normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,108 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reactive;
|
||||||
|
using System.Reactive.Disposables;
|
||||||
|
using System.Reactive.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Artemis.Core;
|
||||||
|
using Artemis.UI.Shared;
|
||||||
|
using Artemis.UI.Shared.Routing;
|
||||||
|
using Avalonia.Controls.Documents;
|
||||||
|
using Avalonia.Media;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using ReactiveUI;
|
||||||
|
using Serilog.Events;
|
||||||
|
using Serilog.Formatting.Display;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Screens.Debugger.Routing;
|
||||||
|
|
||||||
|
public class RoutingDebugViewModel : ActivatableViewModelBase
|
||||||
|
{
|
||||||
|
private readonly IRouter _router;
|
||||||
|
private const int MAX_ENTRIES = 1000;
|
||||||
|
private readonly MessageTemplateTextFormatter _formatter;
|
||||||
|
private string? _route;
|
||||||
|
|
||||||
|
public RoutingDebugViewModel(IRouter router)
|
||||||
|
{
|
||||||
|
_router = router;
|
||||||
|
DisplayName = "Routing";
|
||||||
|
Navigate = ReactiveCommand.CreateFromTask(ExecuteNavigate, this.WhenAnyValue(vm => vm.Route).Select(r => !string.IsNullOrWhiteSpace(r)));
|
||||||
|
|
||||||
|
_formatter = new MessageTemplateTextFormatter(
|
||||||
|
"[{Timestamp:yyyy-MM-dd HH:mm:ss.fff}] [{Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (LogEvent logEvent in LogStore.Events)
|
||||||
|
AddLogEvent(logEvent);
|
||||||
|
|
||||||
|
this.WhenActivated(disp =>
|
||||||
|
{
|
||||||
|
LogStore.EventAdded += OnLogEventAdded;
|
||||||
|
Disposable.Create(() => LogStore.EventAdded -= OnLogEventAdded).DisposeWith(disp);
|
||||||
|
|
||||||
|
_router.CurrentPath.Subscribe(p => Route = p).DisposeWith(disp);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public InlineCollection Lines { get; } = new();
|
||||||
|
public ReactiveCommand<Unit, Unit> Navigate { get; }
|
||||||
|
|
||||||
|
public string? Route
|
||||||
|
{
|
||||||
|
get => _route;
|
||||||
|
set => RaiseAndSetIfChanged(ref _route, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLogEventAdded(object? sender, LogEventEventArgs e)
|
||||||
|
{
|
||||||
|
Dispatcher.UIThread.Post(() => AddLogEvent(e.LogEvent));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddLogEvent(LogEvent? logEvent)
|
||||||
|
{
|
||||||
|
if (logEvent is null)
|
||||||
|
return;
|
||||||
|
if (!logEvent.Properties.TryGetValue("SourceContext", out LogEventPropertyValue? sourceContext) || sourceContext.ToString() != "\"Artemis.UI.Shared.Routing.Navigation\"")
|
||||||
|
return;
|
||||||
|
|
||||||
|
using StringWriter writer = new();
|
||||||
|
_formatter.Format(logEvent, writer);
|
||||||
|
string line = writer.ToString();
|
||||||
|
|
||||||
|
Lines.Add(new Run(line.TrimEnd('\r', '\n') + '\n')
|
||||||
|
{
|
||||||
|
Foreground = logEvent.Level switch
|
||||||
|
{
|
||||||
|
LogEventLevel.Verbose => new SolidColorBrush(Colors.White),
|
||||||
|
LogEventLevel.Debug => new SolidColorBrush(Color.FromRgb(216, 216, 216)),
|
||||||
|
LogEventLevel.Information => new SolidColorBrush(Color.FromRgb(93, 201, 255)),
|
||||||
|
LogEventLevel.Warning => new SolidColorBrush(Color.FromRgb(255, 177, 53)),
|
||||||
|
LogEventLevel.Error => new SolidColorBrush(Color.FromRgb(255, 63, 63)),
|
||||||
|
LogEventLevel.Fatal => new SolidColorBrush(Colors.Red),
|
||||||
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
LimitLines();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LimitLines()
|
||||||
|
{
|
||||||
|
if (Lines.Count > MAX_ENTRIES)
|
||||||
|
Lines.RemoveRange(0, Lines.Count - MAX_ENTRIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ExecuteNavigate(CancellationToken arg)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Route != null)
|
||||||
|
await _router.Navigate(Route.Trim());
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -42,7 +42,15 @@ public class SidebarProfileConfigurationViewModel : ActivatableViewModelBase
|
|||||||
.Select(p => p == null)
|
.Select(p => p == null)
|
||||||
.ToProperty(this, vm => vm.IsDisabled)
|
.ToProperty(this, vm => vm.IsDisabled)
|
||||||
.DisposeWith(d));
|
.DisposeWith(d));
|
||||||
_profileService.LoadProfileConfigurationIcon(ProfileConfiguration);
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_profileService.LoadProfileConfigurationIcon(ProfileConfiguration);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// ignored, too bad but don't crash over corrupt icons
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileConfiguration ProfileConfiguration { get; }
|
public ProfileConfiguration ProfileConfiguration { get; }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user