Skip to content

Commit 0af5f6d

Browse files
committed
添加 Github Release 发行说明显示
1 parent 1a89347 commit 0af5f6d

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

Settings/ReleaseItem.xaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Page
3+
x:Class="Edge.ReleaseItem"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:Edge"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:labs="using:CommunityToolkit.Labs.WinUI.MarkdownTextBlock"
10+
mc:Ignorable="d">
11+
<ScrollView>
12+
<StackPanel Spacing="5" Margin="10">
13+
<HyperlinkButton
14+
Content="在 Github 上查看更详细的发行说明"
15+
NavigateUri="https://github.com/wtcpython/WinUIEdge/releases" />
16+
<labs:MarkdownTextBlock x:Name="markdown" />
17+
</StackPanel>
18+
</ScrollView>
19+
</Page>

Settings/ReleaseItem.xaml.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using CommunityToolkit.Labs.WinUI.MarkdownTextBlock;
2+
using Microsoft.UI.Xaml.Controls;
3+
using System.Collections.Generic;
4+
using System.Net.Http;
5+
using System.Text.Json;
6+
using System.Threading.Tasks;
7+
8+
9+
namespace Edge
10+
{
11+
public class GitHubRelease
12+
{
13+
public string name { get; set; }
14+
public string body { get; set; }
15+
}
16+
17+
public sealed partial class ReleaseItem : Page
18+
{
19+
public ReleaseItem()
20+
{
21+
this.InitializeComponent();
22+
markdown.Config = new MarkdownConfig();
23+
SetText();
24+
}
25+
26+
public async void SetText()
27+
{
28+
List<GitHubRelease> releases = await GetReleasesAsync();
29+
string contents = string.Empty;
30+
releases.ForEach(item =>
31+
{
32+
string content = "# " + item.name + "\n" + item.body + "\n";
33+
contents += content;
34+
});
35+
markdown.Text = contents;
36+
}
37+
38+
public static async Task<List<GitHubRelease>> GetReleasesAsync()
39+
{
40+
HttpClient client = new();
41+
client.DefaultRequestHeaders.UserAgent.ParseAdd("WinUIEdge/1.0");
42+
var response = await client.GetAsync("https://api.github.com/repos/wtcpython/WinUIEdge/releases");
43+
44+
if (response.IsSuccessStatusCode)
45+
{
46+
var json = await response.Content.ReadAsStringAsync();
47+
return JsonSerializer.Deserialize<List<GitHubRelease>>(json);
48+
}
49+
return null;
50+
}
51+
}
52+
}

Settings/SettingsPage.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
</NavigationViewItem>
5454
</NavigationView.MenuItems>
5555

56+
<NavigationView.FooterMenuItems>
57+
<NavigationViewItem Content="新增内容" Tag="ReleaseItem">
58+
<NavigationViewItem.Icon>
59+
<FontIcon Glyph="&#xe789;" />
60+
</NavigationViewItem.Icon>
61+
</NavigationViewItem>
62+
</NavigationView.FooterMenuItems>
63+
5664
<Frame x:Name="ContentFrame"/>
5765
</NavigationView>
5866

0 commit comments

Comments
 (0)