diff --git a/Consts/AboutConst.cs b/Consts/AboutConst.cs index dfee073..035eb78 100644 --- a/Consts/AboutConst.cs +++ b/Consts/AboutConst.cs @@ -14,4 +14,6 @@ internal class AboutConst : AboutMultilangConst public static string PolicyButtonUrl => "https://thoughts.teambition.com/share/6264eda98adeb10041b92fda#title=Sheas_Cealer_隐私政策"; public static string AgreementButtonUrl => "https://thoughts.teambition.com/share/6264edd78adeb10041b92fdb#title=Sheas_Cealer_使用协议"; + + internal static string ReleaseApiUrl => "https://api.github.com/repos/SpaceTimee/Sheas-Cealer/releases/latest"; } \ No newline at end of file diff --git a/Wins/AboutWin.xaml b/Wins/AboutWin.xaml index ad9a52e..9b98c41 100644 --- a/Wins/AboutWin.xaml +++ b/Wins/AboutWin.xaml @@ -9,14 +9,14 @@ mc:Ignorable="d" d:DataContext="{d:DesignInstance preses:AboutPres}" Style="{DynamicResource CommonWindow}" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" SizeToContent="Height" Width="500" - KeyDown="AboutWin_KeyDown"> + Loaded="AboutWin_Loaded" KeyDown="AboutWin_KeyDown"> - + diff --git a/Wins/AboutWin.xaml.cs b/Wins/AboutWin.xaml.cs index 6e4784f..32b42bf 100644 --- a/Wins/AboutWin.xaml.cs +++ b/Wins/AboutWin.xaml.cs @@ -1,8 +1,12 @@ using System; using System.Diagnostics; +using System.Net.Http; +using System.Text.Json; +using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using OnaCore; using Sheas_Cealer.Consts; using Sheas_Cealer.Preses; using Sheas_Cealer.Utils; @@ -12,6 +16,7 @@ namespace Sheas_Cealer.Wins; public partial class AboutWin : Window { private readonly AboutPres AboutPres; + private readonly HttpClient AboutClient = new(new HttpClientHandler() { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator }); internal AboutWin() { @@ -24,6 +29,25 @@ public partial class AboutWin : Window IconRemover.RemoveIcon(this); BorderThemeSetter.SetBorderTheme(this, AboutPres.IsLightTheme); } + private async void AboutWin_Loaded(object sender, RoutedEventArgs e) + { + await Task.Run(async () => + { + try + { + AboutClient.DefaultRequestHeaders.Add("User-Agent", "Sheas-Cealer"); + + JsonElement releaseInfoObject = JsonDocument.Parse(await Http.GetAsync(AboutConst.ReleaseApiUrl, AboutClient)).RootElement; + + AboutClient.DefaultRequestHeaders.Clear(); + + foreach (JsonProperty releaseInfoContent in releaseInfoObject.EnumerateObject()) + if (releaseInfoContent.Name == "name" && releaseInfoContent.Value.ToString() != AboutConst.VersionButtonVersionContent) + AboutPres.IsSheasCealerUtd = false; + } + catch { } + }); + } private void AboutButton_Click(object sender, RoutedEventArgs e) {