mirror of
https://github.com/BlossomiShymae/Needlework.Net.git
synced 2025-12-06 18:20:47 +01:00
Merge branch 'main' into release
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
<AvaloniaXamlIlDebuggerLaunch>False</AvaloniaXamlIlDebuggerLaunch>
|
<AvaloniaXamlIlDebuggerLaunch>False</AvaloniaXamlIlDebuggerLaunch>
|
||||||
<ApplicationIcon>app.ico</ApplicationIcon>
|
<ApplicationIcon>app.ico</ApplicationIcon>
|
||||||
<AssemblyName>NeedleworkDotNet</AssemblyName>
|
<AssemblyName>NeedleworkDotNet</AssemblyName>
|
||||||
<AssemblyVersion>0.6.1.0</AssemblyVersion>
|
<AssemblyVersion>0.7.0.0</AssemblyVersion>
|
||||||
<FileVersion>$(AssemblyVersion)</FileVersion>
|
<FileVersion>$(AssemblyVersion)</FileVersion>
|
||||||
<AvaloniaXamlVerboseExceptions>False</AvaloniaXamlVerboseExceptions>
|
<AvaloniaXamlVerboseExceptions>False</AvaloniaXamlVerboseExceptions>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" />
|
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3" />
|
||||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3" />
|
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3" />
|
||||||
<PackageReference Include="AvaloniaEdit.TextMate" Version="11.1.0" />
|
<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="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||||
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0" />
|
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0" />
|
||||||
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.10" />
|
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.10" />
|
||||||
|
|||||||
@@ -1,28 +1,40 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Templates;
|
using Avalonia.Controls.Templates;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace Needlework.Net
|
namespace Needlework.Net
|
||||||
{
|
{
|
||||||
public class ViewLocator : IDataTemplate
|
public class ViewLocator : IDataTemplate
|
||||||
{
|
{
|
||||||
public Control? Build(object? param)
|
private readonly Dictionary<object, Control> _controlCache = [];
|
||||||
{
|
|
||||||
if (param is null) return new TextBlock { Text = "data was null" };
|
|
||||||
|
|
||||||
var name = param.GetType().FullName!
|
public Control Build(object? data)
|
||||||
.Replace("ViewModels", "Views")
|
{
|
||||||
.Replace("ViewModel", "View");
|
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);
|
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)!;
|
if (!_controlCache.TryGetValue(data!, out var res))
|
||||||
else return new TextBlock { Text = "Not Found: " + name };
|
{
|
||||||
|
res ??= (Control)Activator.CreateInstance(type)!;
|
||||||
|
_controlCache[data!] = res;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.DataContext = data;
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Match(object? data)
|
public bool Match(object? data) => data is INotifyPropertyChanged;
|
||||||
{
|
|
||||||
return data is INotifyPropertyChanged;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,10 +51,11 @@ namespace Needlework.Net.ViewModels
|
|||||||
_ => throw new Exception("Method is not selected."),
|
_ => 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 requestBody = WeakReferenceMessenger.Default.Send(new ContentRequestMessage(), "ConsoleRequestEditor").Response;
|
||||||
var content = new StringContent(requestBody, new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"));
|
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 riotAuthentication = new RiotAuthentication(processInfo.RemotingAuthToken);
|
||||||
var responseBody = await response.Content.ReadAsByteArrayAsync();
|
var responseBody = await response.Content.ReadAsByteArrayAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -19,15 +19,12 @@ namespace Needlework.Net.ViewModels
|
|||||||
public SolidColorBrush Color { get; }
|
public SolidColorBrush Color { get; }
|
||||||
public string Path { get; }
|
public string Path { get; }
|
||||||
public OperationViewModel Operation { get; }
|
public OperationViewModel Operation { get; }
|
||||||
|
|
||||||
public ProcessInfo? ProcessInfo { get; }
|
public ProcessInfo? ProcessInfo { get; }
|
||||||
|
|
||||||
[ObservableProperty] private bool _isBusy;
|
[ObservableProperty] private bool _isBusy;
|
||||||
[ObservableProperty] private string? _responsePath;
|
|
||||||
[ObservableProperty] private string? _responseStatus;
|
[ObservableProperty] private Lazy<ResponseViewModel> _response;
|
||||||
[ObservableProperty] private string? _responseAuthentication;
|
|
||||||
[ObservableProperty] private string? _responseUsername;
|
|
||||||
[ObservableProperty] private string? _responsePassword;
|
|
||||||
[ObservableProperty] private string? _responseAuthorization;
|
|
||||||
|
|
||||||
public PathOperationViewModel(PathOperation pathOperation)
|
public PathOperationViewModel(PathOperation pathOperation)
|
||||||
{
|
{
|
||||||
@@ -35,26 +32,7 @@ namespace Needlework.Net.ViewModels
|
|||||||
Color = new SolidColorBrush(GetColor(Method));
|
Color = new SolidColorBrush(GetColor(Method));
|
||||||
Path = pathOperation.Path;
|
Path = pathOperation.Path;
|
||||||
Operation = new OperationViewModel(pathOperation.Operation);
|
Operation = new OperationViewModel(pathOperation.Operation);
|
||||||
ProcessInfo = GetProcessInfo();
|
Response = new(() => new ResponseViewModel(pathOperation.Path));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
@@ -77,7 +55,7 @@ namespace Needlework.Net.ViewModels
|
|||||||
_ => throw new Exception("Method is missing.")
|
_ => throw new Exception("Method is missing.")
|
||||||
};
|
};
|
||||||
|
|
||||||
var processInfo = Connector.GetProcessInfo();
|
var processInfo = ProcessFinder.Get();
|
||||||
var sb = new StringBuilder(Path);
|
var sb = new StringBuilder(Path);
|
||||||
foreach (var pathParameter in Operation.PathParameters)
|
foreach (var pathParameter in Operation.PathParameters)
|
||||||
{
|
{
|
||||||
@@ -99,7 +77,8 @@ namespace Needlework.Net.ViewModels
|
|||||||
var requestBody = WeakReferenceMessenger.Default.Send(new ContentRequestMessage(), "EndpointRequestEditor").Response;
|
var requestBody = WeakReferenceMessenger.Default.Send(new ContentRequestMessage(), "EndpointRequestEditor").Response;
|
||||||
var content = new StringContent(requestBody, new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"));
|
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 riotAuthentication = new RiotAuthentication(processInfo.RemotingAuthToken);
|
||||||
var responseBytes = await response.Content.ReadAsByteArrayAsync();
|
var responseBytes = await response.Content.ReadAsByteArrayAsync();
|
||||||
|
|
||||||
@@ -111,11 +90,11 @@ namespace Needlework.Net.ViewModels
|
|||||||
}
|
}
|
||||||
else WeakReferenceMessenger.Default.Send(new EditorUpdateMessage(new(responseBody, "EndpointResponseEditor")));
|
else WeakReferenceMessenger.Default.Send(new EditorUpdateMessage(new(responseBody, "EndpointResponseEditor")));
|
||||||
|
|
||||||
ResponseStatus = $"{(int)response.StatusCode} {response.StatusCode}";
|
Response.Value.Status = $"{(int)response.StatusCode} {response.StatusCode}";
|
||||||
ResponsePath = $"https://127.0.0.1:{processInfo.AppPort}{uri}";
|
Response.Value.Path = $"https://127.0.0.1:{processInfo.AppPort}{uri}";
|
||||||
ResponseAuthentication = $"Basic {riotAuthentication.Value}";
|
Response.Value.Authentication = Response.Value.Authorization = $"Basic {riotAuthentication.Value}";
|
||||||
ResponseUsername = riotAuthentication.Username;
|
Response.Value.Username = riotAuthentication.Username;
|
||||||
ResponsePassword = riotAuthentication.Password;
|
Response.Value.Password = riotAuthentication.Password;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
35
Needlework.Net/ViewModels/ResponseViewModel.cs
Normal file
35
Needlework.Net/ViewModels/ResponseViewModel.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Primitives;
|
|
||||||
using Avalonia.Styling;
|
using Avalonia.Styling;
|
||||||
using AvaloniaEdit;
|
using AvaloniaEdit;
|
||||||
using CommunityToolkit.Mvvm.Messaging;
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
@@ -31,9 +30,9 @@ public partial class ConsoleView : UserControl, IRecipient<ResponseUpdatedMessag
|
|||||||
message.Reply(_requestEditor!.Text);
|
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");
|
_responseEditor = this.FindControl<TextEditor>("ResponseEditor");
|
||||||
_requestEditor = this.FindControl<TextEditor>("RequestEditor");
|
_requestEditor = this.FindControl<TextEditor>("RequestEditor");
|
||||||
|
|||||||
@@ -95,7 +95,7 @@
|
|||||||
<TextBox Grid.Row="0"
|
<TextBox Grid.Row="0"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
FontSize="12"
|
FontSize="12"
|
||||||
Text="{Binding SelectedPathOperation.ResponsePath}"
|
Text="{Binding SelectedPathOperation.Response.Value.Path}"
|
||||||
IsReadOnly="True"/>
|
IsReadOnly="True"/>
|
||||||
<StackPanel Grid.Row="0"
|
<StackPanel Grid.Row="0"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
@@ -189,7 +189,7 @@
|
|||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="0 0 0 8"
|
Margin="0 0 0 8"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
Text="{Binding SelectedPathOperation.ResponseUsername}" />
|
Text="{Binding SelectedPathOperation.Response.Value.Username}" />
|
||||||
<TextBlock FontSize="12"
|
<TextBlock FontSize="12"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
@@ -201,7 +201,7 @@
|
|||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="0 0 0 8"
|
Margin="0 0 0 8"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
Text="{Binding SelectedPathOperation.ResponsePassword}"/>
|
Text="{Binding SelectedPathOperation.Response.Value.Password}"/>
|
||||||
<TextBlock FontSize="12"
|
<TextBlock FontSize="12"
|
||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
@@ -212,7 +212,7 @@
|
|||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
Text="{Binding SelectedPathOperation.ResponseAuthorization}"/>
|
Text="{Binding SelectedPathOperation.Response.Value.Authorization}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="Schemas">
|
<TabItem Header="Schemas">
|
||||||
@@ -304,22 +304,25 @@
|
|||||||
FontSize="10"
|
FontSize="10"
|
||||||
Padding="12 4 12 4"
|
Padding="12 4 12 4"
|
||||||
Classes="Flat"
|
Classes="Flat"
|
||||||
Content="{Binding SelectedPathOperation.ResponseStatus}"/>
|
Content="{Binding SelectedPathOperation.Response.Value.Status}"/>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Grid Grid.Row="1" Grid.Column="4">
|
<Grid Grid.Row="1" Grid.Column="4">
|
||||||
<TabControl>
|
<controls:BusyArea BusyText="Loading..."
|
||||||
<TabItem Header="Preview">
|
IsBusy="{Binding SelectedPathOperation.IsBusy}">
|
||||||
<avalonEdit:TextEditor
|
<TabControl>
|
||||||
Name="EndpointResponseEditor"
|
<TabItem Header="Preview">
|
||||||
HorizontalScrollBarVisibility="Auto"
|
<avalonEdit:TextEditor
|
||||||
VerticalScrollBarVisibility="Visible"
|
Name="EndpointResponseEditor"
|
||||||
ShowLineNumbers="True"
|
HorizontalScrollBarVisibility="Auto"
|
||||||
IsReadOnly="True"
|
VerticalScrollBarVisibility="Visible"
|
||||||
Text=""
|
ShowLineNumbers="True"
|
||||||
FontSize="12"/>
|
IsReadOnly="True"
|
||||||
</TabItem>
|
Text=""
|
||||||
</TabControl>
|
FontSize="12"/>
|
||||||
|
</TabItem>
|
||||||
|
</TabControl>
|
||||||
|
</controls:BusyArea>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Primitives;
|
|
||||||
using Avalonia.Styling;
|
using Avalonia.Styling;
|
||||||
using AvaloniaEdit;
|
using AvaloniaEdit;
|
||||||
using CommunityToolkit.Mvvm.Messaging;
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
@@ -21,9 +20,9 @@ public partial class EndpointView : UserControl, IRecipient<EditorUpdateMessage>
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate(e);
|
base.OnAttachedToVisualTree(e);
|
||||||
|
|
||||||
var vm = (EndpointViewModel)DataContext!;
|
var vm = (EndpointViewModel)DataContext!;
|
||||||
_requestEditor = this.FindControl<TextEditor>("EndpointRequestEditor");
|
_requestEditor = this.FindControl<TextEditor>("EndpointRequestEditor");
|
||||||
|
|||||||
Reference in New Issue
Block a user