From 4eae0bd9136b16686f93d993ebfb271a3c901e9a Mon Sep 17 00:00:00 2001 From: BlossomiShymae <87099578+BlossomiShymae@users.noreply.github.com> Date: Thu, 22 Aug 2024 19:26:11 -0500 Subject: [PATCH 1/9] Update GrrrLCU --- Needlework.Net/Needlework.Net.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Needlework.Net/Needlework.Net.csproj b/Needlework.Net/Needlework.Net.csproj index b18e993..4df8978 100644 --- a/Needlework.Net/Needlework.Net.csproj +++ b/Needlework.Net/Needlework.Net.csproj @@ -27,7 +27,7 @@ - + From de6f9f64ddb99a71751fdff7d706d403b106d829 Mon Sep 17 00:00:00 2001 From: BlossomiShymae <87099578+BlossomiShymae@users.noreply.github.com> Date: Thu, 22 Aug 2024 19:39:27 -0500 Subject: [PATCH 2/9] Fix use of GrrrLCU --- Needlework.Net/ViewModels/ConsoleViewModel.cs | 5 +++-- Needlework.Net/ViewModels/PathOperationViewModel.cs | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Needlework.Net/ViewModels/ConsoleViewModel.cs b/Needlework.Net/ViewModels/ConsoleViewModel.cs index abadfbd..8ac1fcb 100644 --- a/Needlework.Net/ViewModels/ConsoleViewModel.cs +++ b/Needlework.Net/ViewModels/ConsoleViewModel.cs @@ -51,10 +51,11 @@ namespace Needlework.Net.ViewModels _ => throw new Exception("Method is not selected."), }; - var processInfo = Connector.GetProcessInfo(); + var processInfo = ProcessFinder.Get(); var requestBody = WeakReferenceMessenger.Default.Send(new ContentRequestMessage(), "ConsoleRequestEditor").Response; var content = new StringContent(requestBody, new System.Net.Http.Headers.MediaTypeHeaderValue("application/json")); - var response = await Connector.SendAsync(method, RequestPath, content); + var client = Connector.GetLcuHttpClientInstance(); + var response = await client.SendAsync(new(method, RequestPath) { Content = content }); var riotAuthentication = new RiotAuthentication(processInfo.RemotingAuthToken); var responseBody = await response.Content.ReadAsByteArrayAsync(); diff --git a/Needlework.Net/ViewModels/PathOperationViewModel.cs b/Needlework.Net/ViewModels/PathOperationViewModel.cs index 2482058..f179c53 100644 --- a/Needlework.Net/ViewModels/PathOperationViewModel.cs +++ b/Needlework.Net/ViewModels/PathOperationViewModel.cs @@ -50,7 +50,7 @@ namespace Needlework.Net.ViewModels { try { - var processInfo = Connector.GetProcessInfo(); + var processInfo = ProcessFinder.Get(); return processInfo; } catch (Exception) { } @@ -77,7 +77,7 @@ namespace Needlework.Net.ViewModels _ => throw new Exception("Method is missing.") }; - var processInfo = Connector.GetProcessInfo(); + var processInfo = ProcessFinder.Get(); var sb = new StringBuilder(Path); foreach (var pathParameter in Operation.PathParameters) { @@ -99,7 +99,8 @@ namespace Needlework.Net.ViewModels var requestBody = WeakReferenceMessenger.Default.Send(new ContentRequestMessage(), "EndpointRequestEditor").Response; var content = new StringContent(requestBody, new System.Net.Http.Headers.MediaTypeHeaderValue("application/json")); - var response = await Connector.SendAsync(method, uri, content); + var client = Connector.GetLcuHttpClientInstance(); + var response = await client.SendAsync(new(method, uri) { Content = content }); var riotAuthentication = new RiotAuthentication(processInfo.RemotingAuthToken); var responseBytes = await response.Content.ReadAsByteArrayAsync(); From 59619764c21fb7196076df2efc02b901adc42871 Mon Sep 17 00:00:00 2001 From: BlossomiShymae <87099578+BlossomiShymae@users.noreply.github.com> Date: Thu, 22 Aug 2024 20:15:13 -0500 Subject: [PATCH 3/9] Improve endpoint loading times by using lazy loading --- .../ViewModels/PathOperationViewModel.cs | 40 +++++-------------- .../ViewModels/ResponseViewModel.cs | 35 ++++++++++++++++ Needlework.Net/Views/EndpointView.axaml | 10 ++--- 3 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 Needlework.Net/ViewModels/ResponseViewModel.cs diff --git a/Needlework.Net/ViewModels/PathOperationViewModel.cs b/Needlework.Net/ViewModels/PathOperationViewModel.cs index f179c53..aadd3c7 100644 --- a/Needlework.Net/ViewModels/PathOperationViewModel.cs +++ b/Needlework.Net/ViewModels/PathOperationViewModel.cs @@ -19,15 +19,12 @@ namespace Needlework.Net.ViewModels public SolidColorBrush Color { get; } public string Path { get; } public OperationViewModel Operation { get; } + public ProcessInfo? ProcessInfo { get; } [ObservableProperty] private bool _isBusy; - [ObservableProperty] private string? _responsePath; - [ObservableProperty] private string? _responseStatus; - [ObservableProperty] private string? _responseAuthentication; - [ObservableProperty] private string? _responseUsername; - [ObservableProperty] private string? _responsePassword; - [ObservableProperty] private string? _responseAuthorization; + + [ObservableProperty] private Lazy _response; public PathOperationViewModel(PathOperation pathOperation) { @@ -35,26 +32,7 @@ namespace Needlework.Net.ViewModels Color = new SolidColorBrush(GetColor(Method)); Path = pathOperation.Path; Operation = new OperationViewModel(pathOperation.Operation); - ProcessInfo = GetProcessInfo(); - if (ProcessInfo != null) - { - ResponsePath = $"https://127.0.0.1:{ProcessInfo.AppPort}{Path}"; - var riotAuth = new RiotAuthentication(ProcessInfo.RemotingAuthToken); - ResponseUsername = riotAuth.Username; - ResponsePassword = riotAuth.Password; - ResponseAuthorization = $"Basic {riotAuth.Value}"; - } - } - - private ProcessInfo? GetProcessInfo() - { - try - { - var processInfo = ProcessFinder.Get(); - return processInfo; - } - catch (Exception) { } - return null; + Response = new(() => new ResponseViewModel(pathOperation.Path)); } [RelayCommand] @@ -112,11 +90,11 @@ namespace Needlework.Net.ViewModels } else WeakReferenceMessenger.Default.Send(new EditorUpdateMessage(new(responseBody, "EndpointResponseEditor"))); - ResponseStatus = $"{(int)response.StatusCode} {response.StatusCode}"; - ResponsePath = $"https://127.0.0.1:{processInfo.AppPort}{uri}"; - ResponseAuthentication = $"Basic {riotAuthentication.Value}"; - ResponseUsername = riotAuthentication.Username; - ResponsePassword = riotAuthentication.Password; + Response.Value.Status = $"{(int)response.StatusCode} {response.StatusCode}"; + Response.Value.Path = $"https://127.0.0.1:{processInfo.AppPort}{uri}"; + Response.Value.Authentication = Response.Value.Authorization = $"Basic {riotAuthentication.Value}"; + Response.Value.Username = riotAuthentication.Username; + Response.Value.Password = riotAuthentication.Password; } catch (Exception ex) { diff --git a/Needlework.Net/ViewModels/ResponseViewModel.cs b/Needlework.Net/ViewModels/ResponseViewModel.cs new file mode 100644 index 0000000..815cb47 --- /dev/null +++ b/Needlework.Net/ViewModels/ResponseViewModel.cs @@ -0,0 +1,35 @@ +using BlossomiShymae.GrrrLCU; +using CommunityToolkit.Mvvm.ComponentModel; + +namespace Needlework.Net.ViewModels +{ + public partial class ResponseViewModel : ObservableObject + { + [ObservableProperty] private string? _path; + [ObservableProperty] private string? _status; + [ObservableProperty] private string? _authentication; + [ObservableProperty] private string? _username; + [ObservableProperty] private string? _password; + [ObservableProperty] private string? _authorization; + + public ResponseViewModel(string path) + { + Path = path; + var processInfo = GetProcessInfo(); + if (processInfo != null) + { + var riotAuthentication = new RiotAuthentication(processInfo.RemotingAuthToken); + Path = $"https://127.0.0.1:{processInfo.AppPort}{path}"; + Username = riotAuthentication.Username; + Password = riotAuthentication.Password; + Authorization = $"Basic {riotAuthentication.RawValue}"; + } + } + + private static ProcessInfo? GetProcessInfo() + { + if (ProcessFinder.IsActive()) return ProcessFinder.Get(); + return null; + } + } +} diff --git a/Needlework.Net/Views/EndpointView.axaml b/Needlework.Net/Views/EndpointView.axaml index 1bcc3bd..f870014 100644 --- a/Needlework.Net/Views/EndpointView.axaml +++ b/Needlework.Net/Views/EndpointView.axaml @@ -95,7 +95,7 @@ + Text="{Binding SelectedPathOperation.Response.Value.Username}" /> + Text="{Binding SelectedPathOperation.Response.Value.Password}"/> + Text="{Binding SelectedPathOperation.Response.Value.Authorization}"/> @@ -304,7 +304,7 @@ FontSize="10" Padding="12 4 12 4" Classes="Flat" - Content="{Binding SelectedPathOperation.ResponseStatus}"/> + Content="{Binding SelectedPathOperation.Response.Value.Status}"/> From b6f713c675d06ad6e18b601c6601b39d9c23dd39 Mon Sep 17 00:00:00 2001 From: BlossomiShymae <87099578+BlossomiShymae@users.noreply.github.com> Date: Fri, 23 Aug 2024 19:39:49 -0500 Subject: [PATCH 4/9] Update GrrrLCU --- Needlework.Net/Needlework.Net.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Needlework.Net/Needlework.Net.csproj b/Needlework.Net/Needlework.Net.csproj index 4df8978..6fa21fa 100644 --- a/Needlework.Net/Needlework.Net.csproj +++ b/Needlework.Net/Needlework.Net.csproj @@ -27,7 +27,7 @@ - + From 48751efc286ebd3dccb7b9463499cc1e175f0842 Mon Sep 17 00:00:00 2001 From: BlossomiShymae <87099578+BlossomiShymae@users.noreply.github.com> Date: Fri, 23 Aug 2024 20:03:18 -0500 Subject: [PATCH 5/9] Fix endpoints not retaining state --- Needlework.Net/ViewLocator.cs | 36 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/Needlework.Net/ViewLocator.cs b/Needlework.Net/ViewLocator.cs index 96e0e11..a4cfcaf 100644 --- a/Needlework.Net/ViewLocator.cs +++ b/Needlework.Net/ViewLocator.cs @@ -1,28 +1,40 @@ using Avalonia.Controls; using Avalonia.Controls.Templates; using System; +using System.Collections.Generic; using System.ComponentModel; namespace Needlework.Net { public class ViewLocator : IDataTemplate { - public Control? Build(object? param) - { - if (param is null) return new TextBlock { Text = "data was null" }; + private readonly Dictionary _controlCache = []; - var name = param.GetType().FullName! - .Replace("ViewModels", "Views") - .Replace("ViewModel", "View"); + public Control Build(object? data) + { + var fullName = data?.GetType().FullName; + if (fullName is null) + { + return new TextBlock { Text = "Data is null or has no name." }; + } + + var name = fullName.Replace("ViewModel", "View"); var type = Type.GetType(name); + if (type is null) + { + return new TextBlock { Text = $"No View For {name}." }; + } - if (type != null) return (Control)Activator.CreateInstance(type)!; - else return new TextBlock { Text = "Not Found: " + name }; + if (!_controlCache.TryGetValue(data!, out var res)) + { + res ??= (Control)Activator.CreateInstance(type)!; + _controlCache[data!] = res; + } + + res.DataContext = data; + return res; } - public bool Match(object? data) - { - return data is INotifyPropertyChanged; - } + public bool Match(object? data) => data is INotifyPropertyChanged; } } From 335274073357ceb2e88ba1644ca317f79f4406bc Mon Sep 17 00:00:00 2001 From: BlossomiShymae <87099578+BlossomiShymae@users.noreply.github.com> Date: Fri, 23 Aug 2024 20:26:08 -0500 Subject: [PATCH 6/9] Add busy area for sending request in endpoint --- Needlework.Net/Views/EndpointView.axaml | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Needlework.Net/Views/EndpointView.axaml b/Needlework.Net/Views/EndpointView.axaml index f870014..5135d79 100644 --- a/Needlework.Net/Views/EndpointView.axaml +++ b/Needlework.Net/Views/EndpointView.axaml @@ -308,18 +308,21 @@ - - - - - + + + + + + + From c0978905884c064a9a166352431896eb950e3689 Mon Sep 17 00:00:00 2001 From: BlossomiShymae <87099578+BlossomiShymae@users.noreply.github.com> Date: Fri, 23 Aug 2024 21:21:01 -0500 Subject: [PATCH 7/9] Fix issues where messages failed to register --- Needlework.Net/Views/ConsoleView.axaml.cs | 5 ++--- Needlework.Net/Views/EndpointView.axaml.cs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Needlework.Net/Views/ConsoleView.axaml.cs b/Needlework.Net/Views/ConsoleView.axaml.cs index 6aacf54..9aa5cae 100644 --- a/Needlework.Net/Views/ConsoleView.axaml.cs +++ b/Needlework.Net/Views/ConsoleView.axaml.cs @@ -1,6 +1,5 @@ using Avalonia; using Avalonia.Controls; -using Avalonia.Controls.Primitives; using Avalonia.Styling; using AvaloniaEdit; using CommunityToolkit.Mvvm.Messaging; @@ -31,9 +30,9 @@ public partial class ConsoleView : UserControl, IRecipient("ResponseEditor"); _requestEditor = this.FindControl("RequestEditor"); diff --git a/Needlework.Net/Views/EndpointView.axaml.cs b/Needlework.Net/Views/EndpointView.axaml.cs index f436c95..3708d3b 100644 --- a/Needlework.Net/Views/EndpointView.axaml.cs +++ b/Needlework.Net/Views/EndpointView.axaml.cs @@ -1,6 +1,5 @@ using Avalonia; using Avalonia.Controls; -using Avalonia.Controls.Primitives; using Avalonia.Styling; using AvaloniaEdit; using CommunityToolkit.Mvvm.Messaging; @@ -21,9 +20,9 @@ public partial class EndpointView : UserControl, IRecipient InitializeComponent(); } - protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { - base.OnApplyTemplate(e); + base.OnAttachedToVisualTree(e); var vm = (EndpointViewModel)DataContext!; _requestEditor = this.FindControl("EndpointRequestEditor"); From 3ec277bdd323f905c3d44ee21b0b2d69c80666c1 Mon Sep 17 00:00:00 2001 From: BlossomiShymae <87099578+BlossomiShymae@users.noreply.github.com> Date: Fri, 23 Aug 2024 22:50:58 -0500 Subject: [PATCH 8/9] Update GrrrLCU --- Needlework.Net/Needlework.Net.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Needlework.Net/Needlework.Net.csproj b/Needlework.Net/Needlework.Net.csproj index 6fa21fa..dfa5125 100644 --- a/Needlework.Net/Needlework.Net.csproj +++ b/Needlework.Net/Needlework.Net.csproj @@ -27,7 +27,7 @@ - + From 375285067de05ac361d24deb5b0bc97db290f97f Mon Sep 17 00:00:00 2001 From: BlossomiShymae <87099578+BlossomiShymae@users.noreply.github.com> Date: Fri, 23 Aug 2024 22:53:05 -0500 Subject: [PATCH 9/9] Bump version --- Needlework.Net/Needlework.Net.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Needlework.Net/Needlework.Net.csproj b/Needlework.Net/Needlework.Net.csproj index dfa5125..1a7beb8 100644 --- a/Needlework.Net/Needlework.Net.csproj +++ b/Needlework.Net/Needlework.Net.csproj @@ -11,7 +11,7 @@ False app.ico NeedleworkDotNet - 0.6.1.0 + 0.7.0.0 $(AssemblyVersion) False