mirror of
https://github.com/BlossomiShymae/Needlework.Net.git
synced 2025-12-06 18:20:47 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0a2685dcf | ||
|
|
ca2f8c4852 | ||
|
|
8f81aa526e | ||
|
|
360a0f28c7 | ||
|
|
4d6e04acb8 | ||
|
|
dc538ee5ce | ||
|
|
16d18878e0 | ||
|
|
893f226463 |
12
Needlework.Net.Desktop/GithubRelease.cs
Normal file
12
Needlework.Net.Desktop/GithubRelease.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Needlework.Net.Desktop
|
||||||
|
{
|
||||||
|
public class GithubRelease
|
||||||
|
{
|
||||||
|
[JsonPropertyName("tag_name")]
|
||||||
|
public string TagName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public bool IsLatest(int version) => int.Parse(TagName.Replace(".", "")) > version;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,10 +9,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Label="Avalonia">
|
<PropertyGroup Label="Avalonia">
|
||||||
<AvaloniaXamlIlDebuggerLaunch>False</AvaloniaXamlIlDebuggerLaunch>
|
<AvaloniaXamlIlDebuggerLaunch>False</AvaloniaXamlIlDebuggerLaunch>
|
||||||
<ApplicationIcon>app.ico</ApplicationIcon>
|
<ApplicationIcon>app.ico</ApplicationIcon>
|
||||||
<AssemblyName>NeedleworkDotNet</AssemblyName>
|
<AssemblyName>NeedleworkDotNet</AssemblyName>
|
||||||
<AssemblyVersion>0.1.1.0</AssemblyVersion>
|
<AssemblyVersion>0.3.1.0</AssemblyVersion>
|
||||||
<FileVersion>0.1.1.0</FileVersion>
|
<FileVersion>0.3.1.0</FileVersion>
|
||||||
<AvaloniaXamlVerboseExceptions>False</AvaloniaXamlVerboseExceptions>
|
<AvaloniaXamlVerboseExceptions>False</AvaloniaXamlVerboseExceptions>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,11 @@ namespace Needlework.Net.Desktop.ViewModels
|
|||||||
var body = await response.Content.ReadAsStringAsync();
|
var body = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
body = !string.IsNullOrEmpty(body) ? JsonSerializer.Serialize(JsonSerializer.Deserialize<object>(body), App.JsonSerializerOptions) : string.Empty;
|
body = !string.IsNullOrEmpty(body) ? JsonSerializer.Serialize(JsonSerializer.Deserialize<object>(body), App.JsonSerializerOptions) : string.Empty;
|
||||||
if (body.Length >= App.MaxCharacters) WindowService.ShowOopsiesWindow(body);
|
if (body.Length >= App.MaxCharacters)
|
||||||
|
{
|
||||||
|
WindowService.ShowOopsiesWindow(body);
|
||||||
|
WeakReferenceMessenger.Default.Send(new ResponseUpdatedMessage(string.Empty), nameof(ConsoleViewModel));
|
||||||
|
}
|
||||||
else WeakReferenceMessenger.Default.Send(new ResponseUpdatedMessage(body), nameof(ConsoleViewModel));
|
else WeakReferenceMessenger.Default.Send(new ResponseUpdatedMessage(body), nameof(ConsoleViewModel));
|
||||||
|
|
||||||
ResponseStatus = $"{(int)response.StatusCode} {response.StatusCode.ToString()}";
|
ResponseStatus = $"{(int)response.StatusCode} {response.StatusCode.ToString()}";
|
||||||
|
|||||||
@@ -12,15 +12,31 @@ namespace Needlework.Net.Desktop.ViewModels
|
|||||||
public string Endpoint { get; }
|
public string Endpoint { get; }
|
||||||
public string Title => Endpoint;
|
public string Title => Endpoint;
|
||||||
|
|
||||||
|
|
||||||
[ObservableProperty] private IAvaloniaReadOnlyList<PathOperationViewModel> _pathOperations;
|
[ObservableProperty] private IAvaloniaReadOnlyList<PathOperationViewModel> _pathOperations;
|
||||||
[ObservableProperty] private PathOperationViewModel? _selectedPathOperation;
|
[ObservableProperty] private PathOperationViewModel? _selectedPathOperation;
|
||||||
|
|
||||||
|
[ObservableProperty] private string? _search;
|
||||||
|
[ObservableProperty] private IAvaloniaReadOnlyList<PathOperationViewModel> _filteredPathOperations;
|
||||||
|
|
||||||
public EndpointViewModel(string endpoint)
|
public EndpointViewModel(string endpoint)
|
||||||
{
|
{
|
||||||
Endpoint = endpoint;
|
Endpoint = endpoint;
|
||||||
|
|
||||||
var handler = WeakReferenceMessenger.Default.Send<DataRequestMessage>().Response;
|
var handler = WeakReferenceMessenger.Default.Send<DataRequestMessage>().Response;
|
||||||
PathOperations = new AvaloniaList<PathOperationViewModel>(handler.Plugins[endpoint].Select(x => new PathOperationViewModel(x)));
|
PathOperations = new AvaloniaList<PathOperationViewModel>(handler.Plugins[endpoint].Select(x => new PathOperationViewModel(x)));
|
||||||
|
FilteredPathOperations = new AvaloniaList<PathOperationViewModel>(PathOperations);
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnSearchChanged(string? value)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
{
|
||||||
|
FilteredPathOperations = new AvaloniaList<PathOperationViewModel>(PathOperations);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FilteredPathOperations = new AvaloniaList<PathOperationViewModel>(PathOperations.Where(o => o.Path.ToLower().Contains(value.ToLower())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Json;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Needlework.Net.Desktop.ViewModels
|
namespace Needlework.Net.Desktop.ViewModels
|
||||||
@@ -28,6 +30,7 @@ namespace Needlework.Net.Desktop.ViewModels
|
|||||||
public OpenApiDocument? HostDocument { get; set; }
|
public OpenApiDocument? HostDocument { get; set; }
|
||||||
|
|
||||||
[ObservableProperty] private bool _isBusy = true;
|
[ObservableProperty] private bool _isBusy = true;
|
||||||
|
[ObservableProperty] private bool _isUpdateShown = false;
|
||||||
|
|
||||||
public MainWindowViewModel(IEnumerable<PageBase> pages, HttpClient httpClient, WindowService windowService)
|
public MainWindowViewModel(IEnumerable<PageBase> pages, HttpClient httpClient, WindowService windowService)
|
||||||
{
|
{
|
||||||
@@ -36,7 +39,44 @@ namespace Needlework.Net.Desktop.ViewModels
|
|||||||
WindowService = windowService;
|
WindowService = windowService;
|
||||||
|
|
||||||
WeakReferenceMessenger.Default.RegisterAll(this);
|
WeakReferenceMessenger.Default.RegisterAll(this);
|
||||||
|
|
||||||
Task.Run(FetchDataAsync);
|
Task.Run(FetchDataAsync);
|
||||||
|
new Thread(ProcessEvents) { IsBackground = true }.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessEvents(object? obj)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Task.Run(CheckLatestVersionAsync);
|
||||||
|
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(60));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task CheckLatestVersionAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.github.com/repos/BlossomiShymae/Needlework.Net/releases/latest");
|
||||||
|
request.Headers.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("Needlework.Net", Version));
|
||||||
|
|
||||||
|
var response = await HttpClient.SendAsync(request);
|
||||||
|
var release = await response.Content.ReadFromJsonAsync<GithubRelease>();
|
||||||
|
if (release == null) return;
|
||||||
|
|
||||||
|
var currentVersion = int.Parse(Version.Replace(".", ""));
|
||||||
|
|
||||||
|
if (release.IsLatest(currentVersion) && !IsUpdateShown)
|
||||||
|
{
|
||||||
|
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(async () =>
|
||||||
|
{
|
||||||
|
await SukiHost.ShowToast("Needlework.Net Update", $"There is a new version available: {release.TagName}.", SukiUI.Enums.NotificationType.Info, TimeSpan.FromSeconds(10), () => OpenUrl("https://github.com/BlossomiShymae/Needlework.Net/releases"));
|
||||||
|
IsUpdateShown = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task FetchDataAsync()
|
private async Task FetchDataAsync()
|
||||||
@@ -74,12 +114,6 @@ namespace Needlework.Net.Desktop.ViewModels
|
|||||||
process.Start();
|
process.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
|
||||||
private void OpenConsole()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Receive(OopsiesWindowRequestedMessage message)
|
public void Receive(OopsiesWindowRequestedMessage message)
|
||||||
{
|
{
|
||||||
WindowService.ShowOopsiesWindow(message.Value);
|
WindowService.ShowOopsiesWindow(message.Value);
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ namespace Needlework.Net.Desktop.ViewModels
|
|||||||
var pathParameters = new AvaloniaList<ParameterViewModel>();
|
var pathParameters = new AvaloniaList<ParameterViewModel>();
|
||||||
foreach (var parameter in parameters)
|
foreach (var parameter in parameters)
|
||||||
{
|
{
|
||||||
if (parameter.In != location) break;
|
if (parameter.In != location) continue;
|
||||||
pathParameters.Add(new ParameterViewModel(parameter.Name, parameter.Schema.Type, parameter.Required));
|
pathParameters.Add(new ParameterViewModel(parameter.Name, GetSchemaType(parameter.Schema), parameter.Required));
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathParameters;
|
return pathParameters;
|
||||||
|
|||||||
@@ -99,7 +99,11 @@ namespace Needlework.Net.Desktop.ViewModels
|
|||||||
var responseBody = await response.Content.ReadAsStringAsync();
|
var responseBody = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
responseBody = !string.IsNullOrEmpty(responseBody) ? JsonSerializer.Serialize(JsonSerializer.Deserialize<object>(responseBody), App.JsonSerializerOptions) : string.Empty;
|
responseBody = !string.IsNullOrEmpty(responseBody) ? JsonSerializer.Serialize(JsonSerializer.Deserialize<object>(responseBody), App.JsonSerializerOptions) : string.Empty;
|
||||||
if (responseBody.Length >= App.MaxCharacters) WeakReferenceMessenger.Default.Send(new OopsiesWindowRequestedMessage(responseBody));
|
if (responseBody.Length >= App.MaxCharacters)
|
||||||
|
{
|
||||||
|
WeakReferenceMessenger.Default.Send(new OopsiesWindowRequestedMessage(responseBody));
|
||||||
|
WeakReferenceMessenger.Default.Send(new EditorUpdateMessage(new(string.Empty, "EndpointResponseEditor")));
|
||||||
|
}
|
||||||
else WeakReferenceMessenger.Default.Send(new EditorUpdateMessage(new(responseBody, "EndpointResponseEditor")));
|
else WeakReferenceMessenger.Default.Send(new EditorUpdateMessage(new(responseBody, "EndpointResponseEditor")));
|
||||||
|
|
||||||
ResponseStatus = $"{(int)response.StatusCode} {response.StatusCode}";
|
ResponseStatus = $"{(int)response.StatusCode} {response.StatusCode}";
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:suki="clr-namespace:SukiUI.Controls;assembly=SukiUI"
|
xmlns:suki="clr-namespace:SukiUI.Controls;assembly=SukiUI"
|
||||||
|
xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
|
||||||
xmlns:theme="clr-namespace:SukiUI.Theme;assembly=SukiUI"
|
xmlns:theme="clr-namespace:SukiUI.Theme;assembly=SukiUI"
|
||||||
xmlns:vm="using:Needlework.Net.Desktop.ViewModels"
|
xmlns:vm="using:Needlework.Net.Desktop.ViewModels"
|
||||||
xmlns:avalonEdit="https://github.com/avaloniaui/avaloniaedit"
|
xmlns:avalonEdit="https://github.com/avaloniaui/avaloniaedit"
|
||||||
@@ -12,15 +13,22 @@
|
|||||||
<Grid RowDefinitions="auto,*" ColumnDefinitions="3*,2,4*,2,4*">
|
<Grid RowDefinitions="auto,*" ColumnDefinitions="3*,2,4*,2,4*">
|
||||||
<Grid Grid.Row="0"
|
<Grid Grid.Row="0"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
Grid.RowSpan="2"
|
RowDefinitions="*"
|
||||||
RowDefinitions="auto,*"
|
ColumnDefinitions="auto,*">
|
||||||
|
<TextBox Text="{Binding Search}"
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.Column="0"
|
||||||
|
Grid.ColumnSpan="2"/>
|
||||||
|
</Grid>
|
||||||
|
<Grid Grid.Row="1"
|
||||||
|
Grid.Column="0"
|
||||||
|
RowDefinitions="*"
|
||||||
ColumnDefinitions="*">
|
ColumnDefinitions="*">
|
||||||
<ListBox ItemsSource="{Binding PathOperations}"
|
<ListBox ItemsSource="{Binding FilteredPathOperations}"
|
||||||
SelectedItem="{Binding SelectedPathOperation}"
|
SelectedItem="{Binding SelectedPathOperation}"
|
||||||
ScrollViewer.HorizontalScrollBarVisibility="Visible"
|
ScrollViewer.HorizontalScrollBarVisibility="Visible"
|
||||||
Margin="0 0 0 0"
|
Margin="0 0 0 0"
|
||||||
Grid.Row="0"
|
Grid.Row="1"
|
||||||
Grid.RowSpan="2"
|
|
||||||
Grid.Column="0">
|
Grid.Column="0">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
|
|||||||
Reference in New Issue
Block a user