From 72a49b7bf2913aa2fea6b13648a2f5414c02dfef Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sat, 17 Jan 2026 17:05:55 +0800 Subject: [PATCH] =?UTF-8?q?improve:=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/Helpers/AutoUpdateHelper.cs | 135 +++++++++++++++--- Ink Canvas/MainWindow.xaml | 4 +- Ink Canvas/MainWindow_cs/MW_Settings.cs | 4 +- Ink Canvas/Resources/Settings.cs | 1 + .../SettingsViews/StartupPanel.xaml | 3 + .../SettingsViews/StartupPanel.xaml.cs | 70 +++++++-- 6 files changed, 180 insertions(+), 37 deletions(-) diff --git a/Ink Canvas/Helpers/AutoUpdateHelper.cs b/Ink Canvas/Helpers/AutoUpdateHelper.cs index 34093826..788aed3a 100644 --- a/Ink Canvas/Helpers/AutoUpdateHelper.cs +++ b/Ink Canvas/Helpers/AutoUpdateHelper.cs @@ -105,6 +105,71 @@ namespace Ink_Canvas.Helpers } } }, + { UpdateChannel.Preview, new List + { + new UpdateLineGroup + { + GroupName = "GitHub主线", + VersionUrl = "https://github.com/InkCanvasForClass/community-beta/raw/refs/heads/main/AutomaticUpdateVersionControl.txt", + DownloadUrlFormat = "https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip", + LogUrl = "https://github.com/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md" + }, + new UpdateLineGroup + { + GroupName = "bgithub备用", + VersionUrl = "https://bgithub.xyz/InkCanvasForClass/community-beta/raw/refs/heads/main/AutomaticUpdateVersionControl.txt", + DownloadUrlFormat = "https://bgithub.xyz/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip", + LogUrl = "https://bgithub.xyz/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md" + }, + new UpdateLineGroup + { + GroupName = "kkgithub线路", + VersionUrl = "https://kkgithub.com/InkCanvasForClass/community-beta/raw/refs/heads/main/AutomaticUpdateVersionControl.txt", + DownloadUrlFormat = "https://kkgithub.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip", + LogUrl = "https://kkgithub.com/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md" + }, + new UpdateLineGroup + { + GroupName = "智教联盟", + DownloadUrlFormat = "https://get.smart-teach.cn/d/Ningbo-S3/shared/jiangling/community-beta/InkCanvasForClass.CE.{0}.zip", + LogUrl = "https://bgithub.xyz/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md" + }, + new UpdateLineGroup + { + GroupName = "inkeys", + DownloadUrlFormat = "https://iccce.inkeys.top/Beta/InkCanvasForClass.CE.{0}.zip", + LogUrl = "https://bgithub.xyz/InkCanvasForClass/community-beta/raw/refs/heads/main/UpdateLog.md" + }, + new UpdateLineGroup + { + GroupName = "gh-proxy", + VersionUrl = "https://gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt", + DownloadUrlFormat = "https://gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip", + LogUrl = "https://gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md" + }, + new UpdateLineGroup + { + GroupName = "hk.gh-proxy", + VersionUrl = "https://hk.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt", + DownloadUrlFormat = "https://hk.gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip", + LogUrl = "https://hk.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md" + }, + new UpdateLineGroup + { + GroupName = "cdn.gh-proxy", + VersionUrl = "https://cdn.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt", + DownloadUrlFormat = "https://cdn.gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip", + LogUrl = "https://cdn.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md" + }, + new UpdateLineGroup + { + GroupName = "edgeone.gh-proxy", + VersionUrl = "https://edgeone.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/AutomaticUpdateVersionControl.txt", + DownloadUrlFormat = "https://edgeone.gh-proxy.org/https://github.com/InkCanvasForClass/community-beta/releases/download/{0}/InkCanvasForClass.CE.{0}.zip", + LogUrl = "https://edgeone.gh-proxy.org/https://raw.githubusercontent.com/InkCanvasForClass/community-beta/refs/heads/main/UpdateLog.md" + } + } + }, { UpdateChannel.Beta, new List { new UpdateLineGroup @@ -527,7 +592,7 @@ namespace Ink_Canvas.Helpers { try { - string apiUrl = channel == UpdateChannel.Beta + string apiUrl = (channel == UpdateChannel.Beta || channel == UpdateChannel.Preview) ? "https://api.github.com/repos/InkCanvasForClass/community-beta/releases" : "https://api.github.com/repos/InkCanvasForClass/community/releases"; using (var client = new HttpClient()) @@ -569,28 +634,58 @@ namespace Ink_Canvas.Helpers { try { - string apiUrl = channel == UpdateChannel.Beta - ? "https://api.github.com/repos/InkCanvasForClass/community-beta/releases/latest" - : "https://api.github.com/repos/InkCanvasForClass/community/releases/latest"; - using (var client = new HttpClient()) + if (channel == UpdateChannel.Beta) { - client.DefaultRequestHeaders.Add("User-Agent", "ICC-CE Auto Updater"); - LogHelper.WriteLogToFile("AutoUpdate | 使用GitHub API调用"); - var response = await client.GetStringAsync(apiUrl); - var json = JObject.Parse(response); - string version = json["tag_name"]?.ToString(); - string releaseNotes = json["body"]?.ToString(); - string downloadUrl = json["assets"]?.First?["browser_download_url"]?.ToString(); - - // 解析发布时间 - DateTime? releaseTime = null; - if (json["published_at"] != null && DateTime.TryParse(json["published_at"].ToString(), out DateTime parsedTime)) + string apiUrl = "https://api.github.com/repos/InkCanvasForClass/community-beta/releases"; + using (var client = new HttpClient()) { - releaseTime = parsedTime; + client.DefaultRequestHeaders.Add("User-Agent", "ICC-CE Auto Updater"); + LogHelper.WriteLogToFile("AutoUpdate | 使用GitHub API调用"); + var response = await client.GetStringAsync(apiUrl); + var releases = JArray.Parse(response); + + if (releases.Count > 0) + { + var latestRelease = releases[0]; + string version = latestRelease["tag_name"]?.ToString(); + string releaseNotes = latestRelease["body"]?.ToString(); + string downloadUrl = latestRelease["assets"]?.First?["browser_download_url"]?.ToString(); + + DateTime? releaseTime = null; + if (latestRelease["published_at"] != null && DateTime.TryParse(latestRelease["published_at"].ToString(), out DateTime parsedTime)) + { + releaseTime = parsedTime; + } + + if (!string.IsNullOrEmpty(version) && !string.IsNullOrEmpty(downloadUrl)) + return (version, downloadUrl, releaseNotes, releaseTime); + } } + } + else + { + string apiUrl = channel == UpdateChannel.Preview + ? "https://api.github.com/repos/InkCanvasForClass/community-beta/releases/latest" + : "https://api.github.com/repos/InkCanvasForClass/community/releases/latest"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Add("User-Agent", "ICC-CE Auto Updater"); + LogHelper.WriteLogToFile("AutoUpdate | 使用GitHub API调用"); + var response = await client.GetStringAsync(apiUrl); + var json = JObject.Parse(response); + string version = json["tag_name"]?.ToString(); + string releaseNotes = json["body"]?.ToString(); + string downloadUrl = json["assets"]?.First?["browser_download_url"]?.ToString(); - if (!string.IsNullOrEmpty(version) && !string.IsNullOrEmpty(downloadUrl)) - return (version, downloadUrl, releaseNotes, releaseTime); + DateTime? releaseTime = null; + if (json["published_at"] != null && DateTime.TryParse(json["published_at"].ToString(), out DateTime parsedTime)) + { + releaseTime = parsedTime; + } + + if (!string.IsNullOrEmpty(version) && !string.IsNullOrEmpty(downloadUrl)) + return (version, downloadUrl, releaseNotes, releaseTime); + } } } catch (Exception ex) @@ -2023,7 +2118,7 @@ namespace Ink_Canvas.Helpers var result = new List<(string, string, string)>(); try { - string apiUrl = channel == UpdateChannel.Beta + string apiUrl = (channel == UpdateChannel.Beta || channel == UpdateChannel.Preview) ? "https://api.github.com/repos/InkCanvasForClass/community-beta/releases" : "https://api.github.com/repos/InkCanvasForClass/community/releases"; using (var client = new HttpClient()) diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 04f4bc8b..89cebc2e 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -642,10 +642,12 @@ + - + diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs index b53389fa..47ce396b 100644 --- a/Ink Canvas/MainWindow_cs/MW_Settings.cs +++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs @@ -3827,7 +3827,9 @@ namespace Ink_Canvas if (radioButton != null) { string channel = radioButton.Tag.ToString(); - UpdateChannel newChannel = channel == "Beta" ? UpdateChannel.Beta : UpdateChannel.Release; + UpdateChannel newChannel = channel == "Beta" ? UpdateChannel.Beta + : channel == "Preview" ? UpdateChannel.Preview + : UpdateChannel.Release; // 如果通道没有变化,不需要执行更新检查 if (Settings.Startup.UpdateChannel == newChannel) diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index dc44bae6..537da24e 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -140,6 +140,7 @@ namespace Ink_Canvas public enum UpdateChannel { Release, + Preview, Beta } diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml index bf6f449d..f2e1511c 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml @@ -128,6 +128,9 @@ + + + diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs index 488c49cf..f1fb8fc5 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs @@ -182,11 +182,15 @@ namespace Ink_Canvas.Windows.SettingsViews // 更新通道 if (MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Release) { - UpdateUpdateChannelButtons(true); + UpdateUpdateChannelButtons(UpdateChannel.Release); + } + else if (MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Preview) + { + UpdateUpdateChannelButtons(UpdateChannel.Preview); } else { - UpdateUpdateChannelButtons(false); + UpdateUpdateChannelButtons(UpdateChannel.Beta); } // 仅PPT模式 @@ -356,7 +360,20 @@ namespace Ink_Canvas.Windows.SettingsViews MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", new System.Windows.Controls.RadioButton { Tag = "Release" }, e); // 更新UI状态 - UpdateUpdateChannelButtons(true); + UpdateUpdateChannelButtons(UpdateChannel.Release); + break; + + case "UpdateChannel_Preview": + // 选择预览版 + MainWindowSettingsHelper.UpdateSettingDirectly(() => + { + MainWindow.Settings.Startup.UpdateChannel = UpdateChannel.Preview; + }, "UpdateChannelSelector"); + // 调用 MainWindow 中的方法 + MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", + new System.Windows.Controls.RadioButton { Tag = "Preview" }, e); + // 更新UI状态 + UpdateUpdateChannelButtons(UpdateChannel.Preview); break; case "UpdateChannel_Beta": @@ -369,7 +386,7 @@ namespace Ink_Canvas.Windows.SettingsViews MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked", new System.Windows.Controls.RadioButton { Tag = "Beta" }, e); // 更新UI状态 - UpdateUpdateChannelButtons(false); + UpdateUpdateChannelButtons(UpdateChannel.Beta); break; } } @@ -377,34 +394,46 @@ namespace Ink_Canvas.Windows.SettingsViews /// /// 更新更新通道按钮状态 /// - private void UpdateUpdateChannelButtons(bool isReleaseSelected) + private void UpdateUpdateChannelButtons(UpdateChannel selectedChannel) { try { bool isDarkTheme = ThemeHelper.IsDarkTheme; + var selectedBrush = isDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + var unselectedBrush = isDarkTheme ? new SolidColorBrush(Color.FromRgb(35, 35, 35)) : new SolidColorBrush(Colors.Transparent); if (UpdateChannelReleaseBorder != null) { - UpdateChannelReleaseBorder.Background = isReleaseSelected - ? (isDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))) - : (isDarkTheme ? new SolidColorBrush(Color.FromRgb(35, 35, 35)) : new SolidColorBrush(Colors.Transparent)); + bool isSelected = selectedChannel == UpdateChannel.Release; + UpdateChannelReleaseBorder.Background = isSelected ? selectedBrush : unselectedBrush; var textBlock = UpdateChannelReleaseBorder.Child as TextBlock; if (textBlock != null) { - textBlock.FontWeight = isReleaseSelected ? FontWeights.Bold : FontWeights.Normal; + textBlock.FontWeight = isSelected ? FontWeights.Bold : FontWeights.Normal; + textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush(); + } + } + + if (UpdateChannelPreviewBorder != null) + { + bool isSelected = selectedChannel == UpdateChannel.Preview; + UpdateChannelPreviewBorder.Background = isSelected ? selectedBrush : unselectedBrush; + var textBlock = UpdateChannelPreviewBorder.Child as TextBlock; + if (textBlock != null) + { + textBlock.FontWeight = isSelected ? FontWeights.Bold : FontWeights.Normal; textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush(); } } if (UpdateChannelBetaBorder != null) { - UpdateChannelBetaBorder.Background = !isReleaseSelected - ? (isDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225))) - : (isDarkTheme ? new SolidColorBrush(Color.FromRgb(35, 35, 35)) : new SolidColorBrush(Colors.Transparent)); + bool isSelected = selectedChannel == UpdateChannel.Beta; + UpdateChannelBetaBorder.Background = isSelected ? selectedBrush : unselectedBrush; var textBlock = UpdateChannelBetaBorder.Child as TextBlock; if (textBlock != null) { - textBlock.FontWeight = !isReleaseSelected ? FontWeights.Bold : FontWeights.Normal; + textBlock.FontWeight = isSelected ? FontWeights.Bold : FontWeights.Normal; textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush(); } } @@ -478,11 +507,22 @@ namespace Ink_Canvas.Windows.SettingsViews textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush(); } } + if (UpdateChannelPreviewBorder != null) + { + UpdateChannelPreviewBorder.Background = isDarkTheme + ? ThemeHelper.GetButtonBackgroundBrush() + : new SolidColorBrush(Color.FromRgb(225, 225, 225)); + var textBlock = UpdateChannelPreviewBorder.Child as TextBlock; + if (textBlock != null) + { + textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush(); + } + } if (UpdateChannelBetaBorder != null) { UpdateChannelBetaBorder.Background = isDarkTheme - ? new SolidColorBrush(Color.FromRgb(35, 35, 35)) - : new SolidColorBrush(Colors.Transparent); + ? ThemeHelper.GetButtonBackgroundBrush() + : new SolidColorBrush(Color.FromRgb(225, 225, 225)); var textBlock = UpdateChannelBetaBorder.Child as TextBlock; if (textBlock != null) {