9 Commits

Author SHA1 Message Date
BlossomiShymae
375285067d Bump version 2024-08-23 22:53:05 -05:00
BlossomiShymae
3ec277bdd3 Update GrrrLCU 2024-08-23 22:50:58 -05:00
BlossomiShymae
c097890588 Fix issues where messages failed to register 2024-08-23 21:21:01 -05:00
BlossomiShymae
3352740733 Add busy area for sending request in endpoint 2024-08-23 20:26:08 -05:00
BlossomiShymae
48751efc28 Fix endpoints not retaining state 2024-08-23 20:03:18 -05:00
BlossomiShymae
b6f713c675 Update GrrrLCU 2024-08-23 19:39:49 -05:00
BlossomiShymae
59619764c2 Improve endpoint loading times by using lazy loading 2024-08-22 20:15:13 -05:00
BlossomiShymae
de6f9f64dd Fix use of GrrrLCU 2024-08-22 19:39:27 -05:00
BlossomiShymae
4eae0bd913 Update GrrrLCU 2024-08-22 19:26:11 -05:00
8 changed files with 100 additions and 72 deletions

View File

@@ -11,7 +11,7 @@
<AvaloniaXamlIlDebuggerLaunch>False</AvaloniaXamlIlDebuggerLaunch>
<ApplicationIcon>app.ico</ApplicationIcon>
<AssemblyName>NeedleworkDotNet</AssemblyName>
<AssemblyVersion>0.6.1.0</AssemblyVersion>
<AssemblyVersion>0.7.0.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<AvaloniaXamlVerboseExceptions>False</AvaloniaXamlVerboseExceptions>
</PropertyGroup>
@@ -27,7 +27,7 @@
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3" />
<PackageReference Include="AvaloniaEdit.TextMate" Version="11.1.0" />
<PackageReference Include="BlossomiShymae.GrrrLCU" Version="0.11.1" />
<PackageReference Include="BlossomiShymae.GrrrLCU" Version="0.13.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0" />
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.10" />

View File

@@ -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<object, Control> _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;
}
}

View File

@@ -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();

View File

@@ -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<ResponseViewModel> _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 = Connector.GetProcessInfo();
return processInfo;
}
catch (Exception) { }
return null;
Response = new(() => new ResponseViewModel(pathOperation.Path));
}
[RelayCommand]
@@ -77,7 +55,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 +77,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();
@@ -111,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)
{

View File

@@ -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;
}
}
}

View File

@@ -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<ResponseUpdatedMessag
message.Reply(_requestEditor!.Text);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnApplyTemplate(e);
base.OnAttachedToVisualTree(e);
_responseEditor = this.FindControl<TextEditor>("ResponseEditor");
_requestEditor = this.FindControl<TextEditor>("RequestEditor");

View File

@@ -95,7 +95,7 @@
<TextBox Grid.Row="0"
Grid.Column="1"
FontSize="12"
Text="{Binding SelectedPathOperation.ResponsePath}"
Text="{Binding SelectedPathOperation.Response.Value.Path}"
IsReadOnly="True"/>
<StackPanel Grid.Row="0"
Grid.Column="2"
@@ -189,7 +189,7 @@
Grid.Column="1"
Margin="0 0 0 8"
IsReadOnly="True"
Text="{Binding SelectedPathOperation.ResponseUsername}" />
Text="{Binding SelectedPathOperation.Response.Value.Username}" />
<TextBlock FontSize="12"
Grid.Row="1"
Grid.Column="0"
@@ -201,7 +201,7 @@
Grid.Column="1"
Margin="0 0 0 8"
IsReadOnly="True"
Text="{Binding SelectedPathOperation.ResponsePassword}"/>
Text="{Binding SelectedPathOperation.Response.Value.Password}"/>
<TextBlock FontSize="12"
Grid.Row="2"
Grid.Column="0"
@@ -212,7 +212,7 @@
Grid.Row="2"
Grid.Column="1"
IsReadOnly="True"
Text="{Binding SelectedPathOperation.ResponseAuthorization}"/>
Text="{Binding SelectedPathOperation.Response.Value.Authorization}"/>
</Grid>
</TabItem>
<TabItem Header="Schemas">
@@ -304,22 +304,25 @@
FontSize="10"
Padding="12 4 12 4"
Classes="Flat"
Content="{Binding SelectedPathOperation.ResponseStatus}"/>
Content="{Binding SelectedPathOperation.Response.Value.Status}"/>
</StackPanel>
<Grid Grid.Row="1" Grid.Column="4">
<TabControl>
<TabItem Header="Preview">
<avalonEdit:TextEditor
Name="EndpointResponseEditor"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Visible"
ShowLineNumbers="True"
IsReadOnly="True"
Text=""
FontSize="12"/>
</TabItem>
</TabControl>
<controls:BusyArea BusyText="Loading..."
IsBusy="{Binding SelectedPathOperation.IsBusy}">
<TabControl>
<TabItem Header="Preview">
<avalonEdit:TextEditor
Name="EndpointResponseEditor"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Visible"
ShowLineNumbers="True"
IsReadOnly="True"
Text=""
FontSize="12"/>
</TabItem>
</TabControl>
</controls:BusyArea>
</Grid>
</Grid>
</UserControl>

View File

@@ -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<EditorUpdateMessage>
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<TextEditor>("EndpointRequestEditor");