Skip to content

Commit

Permalink
新增 插件详细信息
Browse files Browse the repository at this point in the history
  • Loading branch information
MakesYT committed Aug 18, 2024
1 parent a226ea0 commit c630c7f
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2"/>
<PackageReference Include="log4net" Version="2.0.17"/>
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1"/>
<PackageReference Include="Microsoft.Extensions.Resilience" Version="8.7.0"/>
Expand Down Expand Up @@ -68,4 +69,9 @@
</Reference>
</ItemGroup>


<ItemGroup>
<AdditionalFiles Include="PluginManagerPage\PluginDetail.axaml" />
</ItemGroup>

</Project>
File renamed without changes.
91 changes: 91 additions & 0 deletions Core/PluginManagerPage/PluginDetail.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<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:pluginCore="clr-namespace:PluginCore;assembly=Core"
xmlns:pluginManagerPage="clr-namespace:KitopiaAvalonia.Converter.PluginManagerPage"
xmlns:pluginManagerPage1="clr-namespace:KitopiaAvalonia.Controls.PluginManagerPage"
xmlns:mdxaml="https://github.com/whistyun/Markdown.Avalonia.Tight"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:DataType="pluginCore:PluginInfo"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
x:Class="KitopiaAvalonia.Controls.PluginManagerPage.PluginDetail">
<UserControl.Resources>
<pluginManagerPage:IconCtr x:Key="IconCtr" />
</UserControl.Resources>
<Border BorderBrush="{DynamicResource SemiColorBorder}" BorderThickness="1"
CornerRadius="{DynamicResource RadiusCardCornerRadius}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" x:DataType="pluginCore:PluginInfo">
<Panel>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
ColumnDefinitions="80,*" x:DataType="pluginCore:PluginInfo"
IsEnabled="{Binding !UnloadFailed}"
RowDefinitions="*,48">
<Image Grid.Column="0" HorizontalAlignment="Center" Margin="0,15,0,0"
VerticalAlignment="Top" Focusable="False" Width="64"
Source="{Binding Icon,Converter={StaticResource IconCtr},ConverterParameter={Binding .}}"
Height="64" />
<StackPanel Grid.Column="1" Margin="0,15,0,5" VerticalAlignment="Top" Spacing="5"
HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal" x:DataType="pluginCore:PluginInfo" Spacing="5">
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Left"
x:DataType="pluginCore:PluginInfo"
Text="{Binding Name}"
FontWeight="Normal" FontSize="18"
Foreground="{DynamicResource DefaultForeground}">
</TextBlock>
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Left"
x:DataType="pluginCore:PluginInfo"
Text="{Binding Version}"
FontWeight="Normal" FontSize="18"
Foreground="{DynamicResource DefaultForeground}">
</TextBlock>
<TextBlock Text=">" FontSize="18"
x:DataType="pluginCore:PluginInfo"
IsVisible="{Binding CanUpdata}">
<TextBlock.Foreground>
<SolidColorBrush Color="{DynamicResource SemiOrange4Color}" />
</TextBlock.Foreground>
</TextBlock>
<TextBlock Text="{Binding CanUpdateVersion }"
x:DataType="pluginCore:PluginInfo" FontSize="18"
IsVisible="{Binding CanUpdata}">
<TextBlock.Foreground>
<SolidColorBrush Color="{DynamicResource SemiOrange4Color}" />
</TextBlock.Foreground>
</TextBlock>
</StackPanel>
<TextBlock VerticalAlignment="Center"
MaxWidth="{Binding $parent.Bounds.Width}"
TextWrapping="Wrap"
x:DataType="pluginCore:PluginInfo"
Text="{Binding Description}" />
<ScrollViewer IsHitTestVisible="False"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
HorizontalScrollBarVisibility="Hidden">

<mdxaml:MarkdownScrollViewer x:DataType="pluginCore:PluginInfo" Markdown="{Binding $parent[pluginManagerPage1:PluginDetail].Markdown}" ></mdxaml:MarkdownScrollViewer>
</ScrollViewer>
<ContentPresenter HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Content="{Binding $parent[pluginManagerPage1:PluginDetail].Content}">
</ContentPresenter>

</StackPanel>

</Grid>


</Panel>

</Border>
</UserControl>
61 changes: 61 additions & 0 deletions Core/PluginManagerPage/PluginDetail.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using Core.SDKs.Services.Plugin;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PluginCore;

namespace KitopiaAvalonia.Controls.PluginManagerPage;

public partial class PluginDetail : UserControl
{
public static AvaloniaProperty<Control> ContentProperty = AvaloniaProperty.Register<PluginDetail, Control>(nameof(Content));
public Control Content
{
get => (Control)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

public static AvaloniaProperty<string> MarkdownProperty = AvaloniaProperty.Register<PluginDetail, string>(nameof(Markdown));
public string Markdown
{
get => (string)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}
public PluginDetail()
{
InitializeComponent();

}

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
if (DataContext is not PluginInfo pluginInfo)
{
return;
}

Task.Run(async () =>
{
var request = new HttpRequestMessage()
{
RequestUri = new Uri($"https://www.ncserver.top:5111/api/plugin/{pluginInfo.Id}"),
Method = HttpMethod.Get,
};
request.Headers.Add("AllBeforeThisVersion", true.ToString());
var sendAsync = await PluginManager._httpClient.SendAsync(request);
var stringAsync = await sendAsync.Content.ReadAsStringAsync();
var deserializeObject = (JObject)JsonConvert.DeserializeObject(stringAsync);
var list = deserializeObject["data"]["description"].ToString();
await Dispatcher.UIThread.InvokeAsync(() =>
{
SetValue(MarkdownProperty, list);
});
});

}
}
65 changes: 63 additions & 2 deletions Core/ViewModel/Pages/plugin/PluginManagerPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Shapes;
using Avalonia.Layout;
using Avalonia.LogicalTree;
using Avalonia.Markup.Xaml.MarkupExtensions;
using Avalonia.Media;
Expand All @@ -19,8 +20,10 @@
using Core.SDKs.Services;
using Core.SDKs.Services.Config;
using Core.SDKs.Services.Plugin;
using KitopiaAvalonia.Controls.PluginManagerPage;
using KitopiaAvalonia.Tools;
using log4net;
using Markdown.Avalonia.Full;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -163,9 +166,9 @@ private async Task ShowPluginVersionInfo(Control control)
Stroke = semiColorBorder2,
EndPoint = new Point( childOfType.Bounds.Width,0)
});
stackPanel.Children.Add( new Label()
stackPanel.Children.Add( new MarkdownScrollViewer()
{
Content = list[i]["detail"]
Markdown = list[i]["detail"].ToString()
});
}
var dialog = new DialogContent()
Expand All @@ -174,6 +177,64 @@ private async Task ShowPluginVersionInfo(Control control)
Title = "版本详细信息",
};

ServiceManager.Services!.GetService<IContentDialog>()!.ShowDialogAsync(childOfType,
dialog,true);
}

}

[RelayCommand]
private async Task ShowPluginDetail(Control control)
{
if (control.DataContext is PluginInfo pluginInfo)
{
StackPanel stackPanel = new StackPanel();
stackPanel.Spacing = 4;

var request = new HttpRequestMessage()
{
RequestUri = new Uri($"https://www.ncserver.top:5111/api/plugin/detail/{pluginInfo.Id}/{pluginInfo.CanUpdateVersionId}"),
Method = HttpMethod.Get,
};
request.Headers.Add("AllBeforeThisVersion",true.ToString());
var sendAsync =await PluginManager._httpClient.SendAsync(request);
var stringAsync =await sendAsync.Content.ReadAsStringAsync();
var deserializeObject = (JObject)JsonConvert.DeserializeObject(stringAsync);
var list = deserializeObject["data"].ToObject<List<JObject>>();

Application.Current.Styles.TryGetResource("TitleLabel",null,out var h1);
Application.Current.Styles.TryGetResource("SemiColorBorder",null,out var semiColorBorder);
var semiColorBorder2 = semiColorBorder as SolidColorBrush;
var controlTheme = h1 as ControlTheme;
var childOfType = control.GetParentOfType<Window>().GetChildOfType<ContentPresenter>("DialogOvercover");
for (var i = 0; i < list.Count; i++)
{
stackPanel.Children.Add( new Label()
{
Classes = { "H3" },
Theme =controlTheme,
Content = list[i]["version"]
});
stackPanel.Children.Add(new Line()
{
Stroke = semiColorBorder2,
EndPoint = new Point( childOfType.Bounds.Width,0)
});
stackPanel.Children.Add( new MarkdownScrollViewer()
{
Markdown = list[i]["detail"].ToString()
});
}
var pluginDetail = new PluginDetail();
pluginDetail.DataContext= pluginInfo;
pluginDetail.Content = stackPanel;
var dialog = new DialogContent()
{
Content =pluginDetail,
Title = "插件详细信息",
};


ServiceManager.Services!.GetService<IContentDialog>()!.ShowDialogAsync(childOfType,
dialog,true);
}
Expand Down
2 changes: 2 additions & 0 deletions KitopiaAvalonia/KitopiaAvalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<PackageReference Include="Irihi.Ursa" Version="1.0.0-rc1"/>
<PackageReference Include="Irihi.Ursa.Themes.Semi" Version="1.0.0-rc1"/>
<PackageReference Include="log4net" Version="2.0.17"/>
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3"/>
<PackageReference Include="System.Drawing.Common" Version="8.0.6"/>
Expand Down Expand Up @@ -107,6 +108,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="Converter\PluginManagerPage\" />
<Folder Include="Tools\" />
</ItemGroup>

Expand Down
17 changes: 12 additions & 5 deletions KitopiaAvalonia/Pages/PluginManagerPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
xmlns:plugin="clr-namespace:Core.ViewModel.Pages.plugin;assembly=Core"
xmlns:marketPage="clr-namespace:KitopiaAvalonia.Converter.MarketPage"
xmlns:pluginManagerPage="clr-namespace:KitopiaAvalonia.Converter.PluginManagerPage"
xmlns:pluginManagerPage1="clr-namespace:KitopiaAvalonia.Converter.PluginManagerPage;assembly=Core"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:DataType="plugin:PluginManagerPageViewModel"
x:Class="KitopiaAvalonia.Pages.PluginManagerPage">

<UserControl.Resources>

<pluginManagerPage:IconCtr x:Key="IconCtr" />
<pluginManagerPage1:IconCtr x:Key="IconCtr" />
</UserControl.Resources>
<Panel>
<ContentPresenter ZIndex="1" x:Name="DialogOvercover"></ContentPresenter>
Expand Down Expand Up @@ -41,10 +42,16 @@
Height="64" />
<StackPanel Grid.Column="1" Margin="0,15,0,5" VerticalAlignment="Top" Spacing="5"
HorizontalAlignment="Stretch">
<TextBlock VerticalAlignment="Center" Focusable="False"
Text="{Binding Path=Name}"
Background="{x:Null}"
FontWeight="Normal" FontSize="18" />
<Button VerticalAlignment="Center"
HorizontalAlignment="Left"
Theme="{DynamicResource BorderlessButton}" Padding="0"
MinHeight="0"
Content="{Binding Name}"
FontWeight="Normal" FontSize="18"
Foreground="{DynamicResource DefaultForeground}"
Command="{Binding Path=$parent[ItemsControl].((plugin:PluginManagerPageViewModel)DataContext).ShowPluginDetailCommand}"
CommandParameter="{Binding $self}">
</Button>
<StackPanel Orientation="Horizontal" Spacing="5">
<TextBlock VerticalAlignment="Top"
Text="{Binding Version}" />
Expand Down

0 comments on commit c630c7f

Please sign in to comment.