From 840eca88c86598106b0fc6f3bc3e244763650161 Mon Sep 17 00:00:00 2001
From: CJKmkp <2564608840@qq.com>
Date: Sat, 7 Feb 2026 14:49:52 +0800
Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../SettingsViews/MainWindowSettingsHelper.cs | 3 -
.../SettingsViews/StartupPanel.xaml | 159 ------
.../SettingsViews/StartupPanel.xaml.cs | 268 ---------
.../SettingsViews/UpdateCenterPanel.xaml | 363 ++++++++----
.../SettingsViews/UpdateCenterPanel.xaml.cs | 516 +++++++++++++++---
5 files changed, 705 insertions(+), 604 deletions(-)
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/MainWindowSettingsHelper.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/MainWindowSettingsHelper.cs
index 244acfdf..98cae9d6 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/MainWindowSettingsHelper.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/MainWindowSettingsHelper.cs
@@ -10,9 +10,6 @@ using Media = System.Windows.Media;
namespace Ink_Canvas.Windows.SettingsViews
{
- ///
- /// 辅助类:用于在新设置面板中调用 MainWindow 中已有的设置处理方法
- ///
public static class MainWindowSettingsHelper
{
private static MainWindow GetMainWindow()
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml
index cda2e1f3..e5629286 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml
@@ -88,165 +88,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs
index 622829ff..72310ac5 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/StartupPanel.xaml.cs
@@ -86,54 +86,6 @@ namespace Ink_Canvas.Windows.SettingsViews
try
{
- // 自动更新设置
- var toggleSwitchIsAutoUpdate = FindToggleSwitch("ToggleSwitchIsAutoUpdate");
- if (toggleSwitchIsAutoUpdate != null)
- {
- bool isAutoUpdate = MainWindow.Settings.Startup.IsAutoUpdate;
- SetToggleSwitchState(toggleSwitchIsAutoUpdate, isAutoUpdate);
- }
-
- // 静默更新设置
- var toggleSwitchIsAutoUpdateWithSilence = FindToggleSwitch("ToggleSwitchIsAutoUpdateWithSilence");
- if (toggleSwitchIsAutoUpdateWithSilence != null)
- {
- bool isAutoUpdateWithSilence = MainWindow.Settings.Startup.IsAutoUpdateWithSilence;
- SetToggleSwitchState(toggleSwitchIsAutoUpdateWithSilence, isAutoUpdateWithSilence);
- toggleSwitchIsAutoUpdateWithSilence.Visibility = MainWindow.Settings.Startup.IsAutoUpdate ? Visibility.Visible : Visibility.Collapsed;
- }
-
- // 静默更新时间段
- if (AutoUpdateTimePeriodBlock != null)
- {
- AutoUpdateTimePeriodBlock.Visibility =
- (MainWindow.Settings.Startup.IsAutoUpdateWithSilence && MainWindow.Settings.Startup.IsAutoUpdate) ?
- Visibility.Visible : Visibility.Collapsed;
- }
-
- // 设置时间选择器
- if (AutoUpdateWithSilenceStartTimeComboBox != null)
- {
- var startTime = MainWindow.Settings.Startup.AutoUpdateWithSilenceStartTime ?? "06:00";
- var startItem = AutoUpdateWithSilenceStartTimeComboBox.Items.Cast()
- .FirstOrDefault(item => item.Tag?.ToString() == startTime.Replace(":", ""));
- if (startItem != null)
- {
- AutoUpdateWithSilenceStartTimeComboBox.SelectedItem = startItem;
- }
- }
-
- if (AutoUpdateWithSilenceEndTimeComboBox != null)
- {
- var endTime = MainWindow.Settings.Startup.AutoUpdateWithSilenceEndTime ?? "22:00";
- var endItem = AutoUpdateWithSilenceEndTimeComboBox.Items.Cast()
- .FirstOrDefault(item => item.Tag?.ToString() == endTime.Replace(":", ""));
- if (endItem != null)
- {
- AutoUpdateWithSilenceEndTimeComboBox.SelectedItem = endItem;
- }
- }
-
// 开机时运行
var toggleSwitchRunAtStartup = FindToggleSwitch("ToggleSwitchRunAtStartup");
if (toggleSwitchRunAtStartup != null)
@@ -179,20 +131,6 @@ namespace Ink_Canvas.Windows.SettingsViews
SetToggleSwitchState(toggleSwitchUIAccessTopMost, MainWindow.Settings.Advanced.EnableUIAccessTopMost);
}
- // 更新通道
- if (MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Release)
- {
- UpdateUpdateChannelButtons(UpdateChannel.Release);
- }
- else if (MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Preview)
- {
- UpdateUpdateChannelButtons(UpdateChannel.Preview);
- }
- else
- {
- UpdateUpdateChannelButtons(UpdateChannel.Beta);
- }
-
// 仅PPT模式
var toggleSwitchMode = FindToggleSwitch("ToggleSwitchMode");
if (toggleSwitchMode != null && MainWindow.Settings.ModeSettings != null)
@@ -241,10 +179,6 @@ namespace Ink_Canvas.Windows.SettingsViews
{
switch (tag)
{
- case "IsAutoUpdate":
- return MainWindow.Settings.Startup?.IsAutoUpdate ?? false;
- case "IsAutoUpdateWithSilence":
- return MainWindow.Settings.Startup?.IsAutoUpdateWithSilence ?? false;
case "RunAtStartup":
// 检查启动项是否存在
return System.IO.File.Exists(
@@ -290,33 +224,6 @@ namespace Ink_Canvas.Windows.SettingsViews
switch (tag)
{
- case "IsAutoUpdate":
- // 直接调用 MainWindow 中的方法
- MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsAutoUpdate", newState);
- // 更新UI状态
- var toggleSwitchIsAutoUpdateWithSilence = FindToggleSwitch("ToggleSwitchIsAutoUpdateWithSilence");
- if (toggleSwitchIsAutoUpdateWithSilence != null)
- {
- toggleSwitchIsAutoUpdateWithSilence.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
- }
- if (AutoUpdateTimePeriodBlock != null)
- {
- AutoUpdateTimePeriodBlock.Visibility =
- (MainWindow.Settings.Startup.IsAutoUpdateWithSilence && MainWindow.Settings.Startup.IsAutoUpdate) ?
- Visibility.Visible : Visibility.Collapsed;
- }
- break;
-
- case "IsAutoUpdateWithSilence":
- // 直接调用 MainWindow 中的方法
- MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsAutoUpdateWithSilence", newState);
- // 更新UI状态
- if (AutoUpdateTimePeriodBlock != null)
- {
- AutoUpdateTimePeriodBlock.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
- }
- break;
-
case "RunAtStartup":
// 直接调用 MainWindow 中的方法
MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchRunAtStartup", newState);
@@ -376,156 +283,6 @@ namespace Ink_Canvas.Windows.SettingsViews
}
}
- ///
- /// 选项按钮点击事件处理
- ///
- private void OptionButton_Click(object sender, RoutedEventArgs e)
- {
- if (!_isLoaded) return;
-
- var border = sender as Border;
- if (border == null) return;
-
- string tag = border.Tag?.ToString();
- if (string.IsNullOrEmpty(tag)) return;
-
- switch (tag)
- {
- case "UpdateChannel_Release":
- // 选择稳定版
- MainWindowSettingsHelper.UpdateSettingDirectly(() =>
- {
- MainWindow.Settings.Startup.UpdateChannel = UpdateChannel.Release;
- }, "UpdateChannelSelector");
- // 调用 MainWindow 中的方法
- MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked",
- new System.Windows.Controls.RadioButton { Tag = "Release" }, e);
- // 更新UI状态
- 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":
- // 选择测试版
- MainWindowSettingsHelper.UpdateSettingDirectly(() =>
- {
- MainWindow.Settings.Startup.UpdateChannel = UpdateChannel.Beta;
- }, "UpdateChannelSelector");
- // 调用 MainWindow 中的方法
- MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked",
- new System.Windows.Controls.RadioButton { Tag = "Beta" }, e);
- // 更新UI状态
- UpdateUpdateChannelButtons(UpdateChannel.Beta);
- break;
- }
- }
-
- ///
- /// 更新更新通道按钮状态
- ///
- private void UpdateUpdateChannelButtons(UpdateChannel selectedChannel)
- {
- try
- {
- bool isDarkTheme = ThemeHelper.IsDarkTheme;
- var selectedBrush = isDarkTheme ? new SolidColorBrush(Color.FromRgb(25, 25, 25)) : new SolidColorBrush(Color.FromRgb(225, 225, 225));
- var unselectedBrush = new SolidColorBrush(Colors.Transparent);
-
- if (UpdateChannelReleaseBorder != null)
- {
- bool isSelected = selectedChannel == UpdateChannel.Release;
- UpdateChannelReleaseBorder.Background = isSelected ? selectedBrush : unselectedBrush;
- var textBlock = UpdateChannelReleaseBorder.Child as TextBlock;
- if (textBlock != null)
- {
- 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)
- {
- bool isSelected = selectedChannel == UpdateChannel.Beta;
- UpdateChannelBetaBorder.Background = isSelected ? selectedBrush : unselectedBrush;
- var textBlock = UpdateChannelBetaBorder.Child as TextBlock;
- if (textBlock != null)
- {
- textBlock.FontWeight = isSelected ? FontWeights.Bold : FontWeights.Normal;
- textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush();
- }
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine($"更新更新通道按钮状态时出错: {ex.Message}");
- }
- }
-
- ///
- /// 手动更新按钮点击事件
- ///
- private async void ManualUpdateButton_Click(object sender, RoutedEventArgs e)
- {
- MainWindowSettingsHelper.InvokeMainWindowMethod("ManualUpdateButton_Click", sender, e);
- }
-
- ///
- /// 版本修复按钮点击事件
- ///
- private async void FixVersionButton_Click(object sender, RoutedEventArgs e)
- {
- MainWindowSettingsHelper.InvokeMainWindowMethod("FixVersionButton_Click", sender, e);
- }
-
- ///
- /// 历史版本回滚按钮点击事件
- ///
- private void HistoryRollbackButton_Click(object sender, RoutedEventArgs e)
- {
- // 查找 MainWindow 中的历史版本回滚方法
- MainWindowSettingsHelper.InvokeMainWindowMethod("HistoryRollbackButton_Click", sender, e);
- }
-
- ///
- /// ComboBox选择变化事件处理
- ///
- private void AutoUpdateWithSilenceStartTimeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!_isLoaded) return;
- // 直接调用 MainWindow 中的方法
- MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("AutoUpdateWithSilenceStartTimeComboBox", AutoUpdateWithSilenceStartTimeComboBox?.SelectedItem);
- }
-
- private void AutoUpdateWithSilenceEndTimeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!_isLoaded) return;
- // 直接调用 MainWindow 中的方法
- MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("AutoUpdateWithSilenceEndTimeComboBox", AutoUpdateWithSilenceEndTimeComboBox?.SelectedItem);
- }
///
/// 应用主题
@@ -534,31 +291,6 @@ namespace Ink_Canvas.Windows.SettingsViews
{
try
{
- bool isDarkTheme = ThemeHelper.IsDarkTheme;
-
- if (MainWindow.Settings?.Startup != null)
- {
- UpdateUpdateChannelButtons(MainWindow.Settings.Startup.UpdateChannel);
- }
-
- // 更新按钮
- if (ManualUpdateButton != null)
- {
- ManualUpdateButton.Background = ThemeHelper.GetButtonBackgroundBrush();
- ManualUpdateButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
- }
- if (FixVersionButton != null)
- {
- FixVersionButton.Background = ThemeHelper.GetButtonBackgroundBrush();
- FixVersionButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
- }
- if (HistoryRollbackButton != null)
- {
- HistoryRollbackButton.Background = ThemeHelper.GetButtonBackgroundBrush();
- HistoryRollbackButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
- }
-
- // 使用 ThemeHelper 递归更新其他元素
ThemeHelper.ApplyThemeToControl(this);
if (_isLoaded)
{
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/UpdateCenterPanel.xaml b/Ink Canvas/Windows/SettingsViews/SettingsViews/UpdateCenterPanel.xaml
index b7fc1e6b..ad92ae6b 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/UpdateCenterPanel.xaml
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/UpdateCenterPanel.xaml
@@ -5,124 +5,269 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Ink_Canvas.Windows.SettingsViews"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
+ xmlns:mdxam="clr-namespace:MdXaml;assembly=MdXaml"
mc:Ignorable="d"
d:DesignHeight="950" d:DesignWidth="640">
-
-
-
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Ink Canvas/Windows/SettingsViews/SettingsViews/UpdateCenterPanel.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsViews/UpdateCenterPanel.xaml.cs
index 9b2ed276..d9bf3a74 100644
--- a/Ink Canvas/Windows/SettingsViews/SettingsViews/UpdateCenterPanel.xaml.cs
+++ b/Ink Canvas/Windows/SettingsViews/SettingsViews/UpdateCenterPanel.xaml.cs
@@ -1,20 +1,22 @@
using iNKORE.UI.WPF.Helpers;
using Ink_Canvas.Helpers;
using System;
+using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Controls.Primitives;
using System.Windows.Media;
-using System.Windows.Media.Animation;
namespace Ink_Canvas.Windows.SettingsViews
{
public partial class UpdateCenterPanel : UserControl
{
- private bool isLoaded = false;
+ private bool _isLoaded = false;
+ private string _currentTab = "Update";
+ private List<(string version, string downloadUrl, string releaseNotes)> _historyVersions = new List<(string, string, string)>();
public UpdateCenterPanel()
{
@@ -24,17 +26,21 @@ namespace Ink_Canvas.Windows.SettingsViews
private void UpdateCenterPanel_Loaded(object sender, RoutedEventArgs e)
{
- if (!isLoaded)
+ if (!_isLoaded)
{
- isLoaded = true;
+ _isLoaded = true;
LoadSettings();
+ SwitchTab("Update");
CheckUpdateStatus();
+ LoadUpdateLog(MainWindow.Settings?.Startup?.UpdateChannel ?? UpdateChannel.Release);
ApplyTheme();
}
}
private void LoadSettings()
{
+ if (MainWindow.Settings == null) return;
+
try
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
@@ -42,6 +48,64 @@ namespace Ink_Canvas.Windows.SettingsViews
CurrentVersionText.Text = $"当前版本: v{version} | {platform}";
LoadLastCheckTime();
+
+ var toggleSwitchIsAutoUpdate = FindToggleSwitch("ToggleSwitchIsAutoUpdate");
+ if (toggleSwitchIsAutoUpdate != null)
+ {
+ bool isAutoUpdate = MainWindow.Settings.Startup.IsAutoUpdate;
+ SetToggleSwitchState(toggleSwitchIsAutoUpdate, isAutoUpdate);
+ }
+
+ var toggleSwitchIsAutoUpdateWithSilence = FindToggleSwitch("ToggleSwitchIsAutoUpdateWithSilence");
+ if (toggleSwitchIsAutoUpdateWithSilence != null)
+ {
+ bool isAutoUpdateWithSilence = MainWindow.Settings.Startup.IsAutoUpdateWithSilence;
+ SetToggleSwitchState(toggleSwitchIsAutoUpdateWithSilence, isAutoUpdateWithSilence);
+ AutoUpdateWithSilencePanel.Visibility = MainWindow.Settings.Startup.IsAutoUpdate ? Visibility.Visible : Visibility.Collapsed;
+ AutoUpdateTimePeriodSeparator.Visibility = MainWindow.Settings.Startup.IsAutoUpdate ? Visibility.Visible : Visibility.Collapsed;
+ }
+
+ if (AutoUpdateTimePeriodBlock != null)
+ {
+ AutoUpdateTimePeriodBlock.Visibility =
+ (MainWindow.Settings.Startup.IsAutoUpdateWithSilence && MainWindow.Settings.Startup.IsAutoUpdate) ?
+ Visibility.Visible : Visibility.Collapsed;
+ }
+
+ if (AutoUpdateWithSilenceStartTimeComboBox != null)
+ {
+ var startTime = MainWindow.Settings.Startup.AutoUpdateWithSilenceStartTime ?? "06:00";
+ var startItem = AutoUpdateWithSilenceStartTimeComboBox.Items.Cast()
+ .FirstOrDefault(item => item.Tag?.ToString() == startTime.Replace(":", ""));
+ if (startItem != null)
+ {
+ AutoUpdateWithSilenceStartTimeComboBox.SelectedItem = startItem;
+ }
+ }
+
+ if (AutoUpdateWithSilenceEndTimeComboBox != null)
+ {
+ var endTime = MainWindow.Settings.Startup.AutoUpdateWithSilenceEndTime ?? "22:00";
+ var endItem = AutoUpdateWithSilenceEndTimeComboBox.Items.Cast()
+ .FirstOrDefault(item => item.Tag?.ToString() == endTime.Replace(":", ""));
+ if (endItem != null)
+ {
+ AutoUpdateWithSilenceEndTimeComboBox.SelectedItem = endItem;
+ }
+ }
+
+ if (MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Release)
+ {
+ UpdateUpdateChannelButtons(UpdateChannel.Release);
+ }
+ else if (MainWindow.Settings.Startup.UpdateChannel == UpdateChannel.Preview)
+ {
+ UpdateUpdateChannelButtons(UpdateChannel.Preview);
+ }
+ else
+ {
+ UpdateUpdateChannelButtons(UpdateChannel.Beta);
+ }
}
catch (Exception ex)
{
@@ -94,6 +158,58 @@ namespace Ink_Canvas.Windows.SettingsViews
}
}
+ private void Tab_Click(object sender, RoutedEventArgs e)
+ {
+ var border = sender as Border;
+ if (border == null) return;
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ SwitchTab(tag);
+ }
+
+ private void SwitchTab(string tabName)
+ {
+ _currentTab = tabName;
+ bool isDarkTheme = ThemeHelper.IsDarkTheme;
+ var selectedBrush = isDarkTheme ? new SolidColorBrush(Color.FromRgb(25, 25, 25)) : new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ var unselectedBrush = new SolidColorBrush(Colors.Transparent);
+
+ TabUpdate.Background = tabName == "Update" ? selectedBrush : unselectedBrush;
+ var updateText = TabUpdate.Child as TextBlock;
+ if (updateText != null)
+ {
+ updateText.FontWeight = tabName == "Update" ? FontWeights.Bold : FontWeights.Normal;
+ updateText.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+
+ TabRollback.Background = tabName == "Rollback" ? selectedBrush : unselectedBrush;
+ var rollbackText = TabRollback.Child as TextBlock;
+ if (rollbackText != null)
+ {
+ rollbackText.FontWeight = tabName == "Rollback" ? FontWeights.Bold : FontWeights.Normal;
+ rollbackText.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+
+ TabSettings.Background = tabName == "Settings" ? selectedBrush : unselectedBrush;
+ var settingsText = TabSettings.Child as TextBlock;
+ if (settingsText != null)
+ {
+ settingsText.FontWeight = tabName == "Settings" ? FontWeights.Bold : FontWeights.Normal;
+ settingsText.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+
+ UpdateTabContent.Visibility = tabName == "Update" ? Visibility.Visible : Visibility.Collapsed;
+ RollbackTabContent.Visibility = tabName == "Rollback" ? Visibility.Visible : Visibility.Collapsed;
+ SettingsTabContent.Visibility = tabName == "Settings" ? Visibility.Visible : Visibility.Collapsed;
+
+ if (tabName == "Rollback" && _historyVersions.Count == 0)
+ {
+ LoadHistoryVersions();
+ }
+ }
+
private void CheckUpdateButton_Click(object sender, RoutedEventArgs e)
{
CheckUpdateStatus(true);
@@ -103,15 +219,7 @@ namespace Ink_Canvas.Windows.SettingsViews
{
try
{
- var mainWindow = Application.Current.MainWindow as MainWindow;
- if (mainWindow != null)
- {
- var method = typeof(MainWindow).GetMethod("CheckForUpdates", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
- if (method != null)
- {
- method.Invoke(mainWindow, null);
- }
- }
+ MainWindowSettingsHelper.InvokeMainWindowMethod("ManualUpdateButton_Click", sender, e);
}
catch (Exception ex)
{
@@ -168,6 +276,15 @@ namespace Ink_Canvas.Windows.SettingsViews
UpdateStatusText.Text = "你使用的是最新版本";
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
}
+
+ if (!string.IsNullOrEmpty(releaseNotes))
+ {
+ UpdateLogViewer.Markdown = releaseNotes;
+ }
+ else
+ {
+ LoadUpdateLog(updateChannel);
+ }
if (manualCheck)
{
@@ -191,6 +308,311 @@ namespace Ink_Canvas.Windows.SettingsViews
});
}
+ private async void LoadUpdateLog(UpdateChannel channel)
+ {
+ try
+ {
+ var updateLog = await AutoUpdateHelper.GetUpdateLog(channel);
+ if (!string.IsNullOrEmpty(updateLog))
+ {
+ UpdateLogViewer.Markdown = updateLog;
+ }
+ else
+ {
+ UpdateLogViewer.Markdown = "暂无更新日志";
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"加载更新日志失败: {ex.Message}");
+ UpdateLogViewer.Markdown = "加载更新日志失败";
+ }
+ }
+
+ private async void LoadHistoryVersions()
+ {
+ try
+ {
+ HistoryLogViewer.Markdown = "正在加载历史版本...";
+ RollbackVersionComboBox.Items.Clear();
+
+ var updateChannel = UpdateChannel.Release;
+ if (MainWindow.Settings?.Startup != null)
+ {
+ updateChannel = MainWindow.Settings.Startup.UpdateChannel;
+ }
+
+ _historyVersions = await AutoUpdateHelper.GetAllGithubReleases(updateChannel);
+
+ if (_historyVersions.Count > 0)
+ {
+ var markdown = new System.Text.StringBuilder();
+ markdown.AppendLine("# 历史版本列表\n");
+
+ foreach (var (version, downloadUrl, releaseNotes) in _historyVersions)
+ {
+ markdown.AppendLine($"## {version}\n");
+ if (!string.IsNullOrEmpty(releaseNotes))
+ {
+ var notes = releaseNotes.Length > 200 ? releaseNotes.Substring(0, 200) + "..." : releaseNotes;
+ markdown.AppendLine(notes);
+ }
+ markdown.AppendLine("\n---\n");
+ }
+
+ HistoryLogViewer.Markdown = markdown.ToString();
+
+ foreach (var (version, downloadUrl, releaseNotes) in _historyVersions)
+ {
+ var item = new ComboBoxItem
+ {
+ Content = version,
+ Tag = (version, downloadUrl, releaseNotes)
+ };
+ RollbackVersionComboBox.Items.Add(item);
+ }
+ }
+ else
+ {
+ HistoryLogViewer.Markdown = "未获取到历史版本信息。";
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"加载历史版本失败: {ex.Message}");
+ HistoryLogViewer.Markdown = "加载历史版本失败";
+ }
+ }
+
+ private void RollbackVersionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (RollbackVersionComboBox.SelectedItem is ComboBoxItem selectedItem && selectedItem.Tag is (string version, string downloadUrl, string releaseNotes))
+ {
+ if (!string.IsNullOrEmpty(releaseNotes))
+ {
+ HistoryLogViewer.Markdown = $"# {version}\n\n{releaseNotes}";
+ }
+ else
+ {
+ HistoryLogViewer.Markdown = $"# {version}\n\n无更新日志";
+ }
+ }
+ }
+
+ private void RollbackButton_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ var updateChannel = UpdateChannel.Release;
+ if (MainWindow.Settings?.Startup != null)
+ {
+ updateChannel = MainWindow.Settings.Startup.UpdateChannel;
+ }
+ var rollbackWindow = new HistoryRollbackWindow(updateChannel);
+ rollbackWindow.ShowDialog();
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"打开历史版本回滚窗口失败: {ex.Message}");
+ }
+ }
+
+ private void FixVersionButton_Click(object sender, RoutedEventArgs e)
+ {
+ MainWindowSettingsHelper.InvokeMainWindowMethod("FixVersionButton_Click", sender, e);
+ }
+
+ private void OptionButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ switch (tag)
+ {
+ case "UpdateChannel_Release":
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ MainWindow.Settings.Startup.UpdateChannel = UpdateChannel.Release;
+ }, "UpdateChannelSelector");
+ MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked",
+ new System.Windows.Controls.RadioButton { Tag = "Release" }, e);
+ UpdateUpdateChannelButtons(UpdateChannel.Release);
+ LoadHistoryVersions();
+ LoadUpdateLog(UpdateChannel.Release);
+ break;
+
+ case "UpdateChannel_Preview":
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ MainWindow.Settings.Startup.UpdateChannel = UpdateChannel.Preview;
+ }, "UpdateChannelSelector");
+ MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked",
+ new System.Windows.Controls.RadioButton { Tag = "Preview" }, e);
+ UpdateUpdateChannelButtons(UpdateChannel.Preview);
+ LoadHistoryVersions();
+ LoadUpdateLog(UpdateChannel.Preview);
+ break;
+
+ case "UpdateChannel_Beta":
+ MainWindowSettingsHelper.UpdateSettingDirectly(() =>
+ {
+ MainWindow.Settings.Startup.UpdateChannel = UpdateChannel.Beta;
+ }, "UpdateChannelSelector");
+ MainWindowSettingsHelper.InvokeMainWindowMethod("UpdateChannelSelector_Checked",
+ new System.Windows.Controls.RadioButton { Tag = "Beta" }, e);
+ UpdateUpdateChannelButtons(UpdateChannel.Beta);
+ LoadHistoryVersions();
+ LoadUpdateLog(UpdateChannel.Beta);
+ break;
+ }
+ }
+
+ private void UpdateUpdateChannelButtons(UpdateChannel selectedChannel)
+ {
+ try
+ {
+ bool isDarkTheme = ThemeHelper.IsDarkTheme;
+ var selectedBrush = isDarkTheme ? new SolidColorBrush(Color.FromRgb(25, 25, 25)) : new SolidColorBrush(Color.FromRgb(225, 225, 225));
+ var unselectedBrush = new SolidColorBrush(Colors.Transparent);
+
+ if (UpdateChannelReleaseBorder != null)
+ {
+ bool isSelected = selectedChannel == UpdateChannel.Release;
+ UpdateChannelReleaseBorder.Background = isSelected ? selectedBrush : unselectedBrush;
+ var textBlock = UpdateChannelReleaseBorder.Child as TextBlock;
+ if (textBlock != null)
+ {
+ 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)
+ {
+ bool isSelected = selectedChannel == UpdateChannel.Beta;
+ UpdateChannelBetaBorder.Background = isSelected ? selectedBrush : unselectedBrush;
+ var textBlock = UpdateChannelBetaBorder.Child as TextBlock;
+ if (textBlock != null)
+ {
+ textBlock.FontWeight = isSelected ? FontWeights.Bold : FontWeights.Normal;
+ textBlock.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ System.Diagnostics.Debug.WriteLine($"更新更新通道按钮状态时出错: {ex.Message}");
+ }
+ }
+
+ private void ToggleSwitch_Click(object sender, RoutedEventArgs e)
+ {
+ if (!_isLoaded) return;
+
+ var border = sender as Border;
+ if (border == null) return;
+
+ string tag = border.Tag?.ToString();
+ if (string.IsNullOrEmpty(tag)) return;
+
+ bool currentState = GetCurrentSettingValue(tag);
+ bool newState = !currentState;
+ SetToggleSwitchState(border, newState);
+
+ switch (tag)
+ {
+ case "IsAutoUpdate":
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsAutoUpdate", newState);
+ AutoUpdateWithSilencePanel.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
+ AutoUpdateTimePeriodSeparator.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
+ if (AutoUpdateTimePeriodBlock != null)
+ {
+ AutoUpdateTimePeriodBlock.Visibility =
+ (MainWindow.Settings.Startup.IsAutoUpdateWithSilence && MainWindow.Settings.Startup.IsAutoUpdate) ?
+ Visibility.Visible : Visibility.Collapsed;
+ }
+ break;
+
+ case "IsAutoUpdateWithSilence":
+ MainWindowSettingsHelper.InvokeToggleSwitchToggled("ToggleSwitchIsAutoUpdateWithSilence", newState);
+ if (AutoUpdateTimePeriodBlock != null)
+ {
+ AutoUpdateTimePeriodBlock.Visibility = newState ? Visibility.Visible : Visibility.Collapsed;
+ }
+ break;
+ }
+ }
+
+ private bool GetCurrentSettingValue(string tag)
+ {
+ if (MainWindow.Settings == null) return false;
+
+ try
+ {
+ switch (tag)
+ {
+ case "IsAutoUpdate":
+ return MainWindow.Settings.Startup?.IsAutoUpdate ?? false;
+ case "IsAutoUpdateWithSilence":
+ return MainWindow.Settings.Startup?.IsAutoUpdateWithSilence ?? false;
+ default:
+ return false;
+ }
+ }
+ catch
+ {
+ return false;
+ }
+ }
+
+ private Border FindToggleSwitch(string name)
+ {
+ return this.FindDescendantByName(name) as Border;
+ }
+
+ private void SetToggleSwitchState(Border toggleSwitch, bool isOn)
+ {
+ if (toggleSwitch == null) return;
+ toggleSwitch.Background = isOn
+ ? new SolidColorBrush(Color.FromRgb(53, 132, 228))
+ : (ThemeHelper.IsDarkTheme ? ThemeHelper.GetButtonBackgroundBrush() : new SolidColorBrush(Color.FromRgb(225, 225, 225)));
+ var innerBorder = toggleSwitch.Child as Border;
+ if (innerBorder != null)
+ {
+ innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
+ innerBorder.Background = new SolidColorBrush(Colors.White);
+ }
+ }
+
+ private void AutoUpdateWithSilenceStartTimeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("AutoUpdateWithSilenceStartTimeComboBox", AutoUpdateWithSilenceStartTimeComboBox?.SelectedItem);
+ }
+
+ private void AutoUpdateWithSilenceEndTimeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (!_isLoaded) return;
+ MainWindowSettingsHelper.InvokeComboBoxSelectionChanged("AutoUpdateWithSilenceEndTimeComboBox", AutoUpdateWithSilenceEndTimeComboBox?.SelectedItem);
+ }
+
public event EventHandler IsTopBarNeedShadowEffect;
public event EventHandler IsTopBarNeedNoShadowEffect;
@@ -207,57 +629,6 @@ namespace Ink_Canvas.Windows.SettingsViews
}
}
- private void ScrollBar_Scroll(object sender, RoutedEventArgs e)
- {
- var scrollbar = (ScrollBar)sender;
- var scrollviewer = scrollbar.FindAscendant();
- if (scrollviewer != null) scrollviewer.ScrollToVerticalOffset(scrollbar.Track.Value);
- }
-
- private void ScrollBarTrack_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
- {
- var border = (Border)sender;
- if (border.Child is Track track)
- {
- track.Width = 16;
- track.Margin = new Thickness(0, 0, -2, 0);
- var scrollbar = track.FindAscendant();
- if (scrollbar != null) scrollbar.Width = 16;
- }
- }
-
- private void ScrollBarTrack_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
- {
- var border = (Border)sender;
- if (border.Child is Track track)
- {
- track.Width = 6;
- track.Margin = new Thickness(0, 0, 0, 0);
- var scrollbar = track.FindAscendant();
- if (scrollbar != null) scrollbar.Width = 6;
- }
- }
-
- private void ScrollbarThumb_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
- {
- var thumb = (System.Windows.Controls.Primitives.Thumb)sender;
- var border = thumb.Template.FindName("ScrollbarThumbEx", thumb);
- if (border is Border borderElement)
- {
- borderElement.Background = new SolidColorBrush(Color.FromRgb(95, 95, 95));
- }
- }
-
- private void ScrollbarThumb_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
- {
- var thumb = (System.Windows.Controls.Primitives.Thumb)sender;
- var border = thumb.Template.FindName("ScrollbarThumbEx", thumb);
- if (border is Border borderElement)
- {
- borderElement.Background = new SolidColorBrush(Color.FromRgb(195, 195, 195));
- }
- }
-
public void ApplyTheme()
{
try
@@ -276,6 +647,20 @@ namespace Ink_Canvas.Windows.SettingsViews
UpdateNowButton.Background = new SolidColorBrush(Color.FromRgb(0, 120, 212));
UpdateNowButton.Foreground = Brushes.White;
}
+
+ if (RollbackButton != null)
+ {
+ RollbackButton.Background = ThemeHelper.GetButtonBackgroundBrush();
+ RollbackButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+
+ if (FixVersionButton != null)
+ {
+ FixVersionButton.Background = ThemeHelper.GetButtonBackgroundBrush();
+ FixVersionButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
+ }
+
+ SwitchTab(_currentTab);
}
catch (Exception ex)
{
@@ -314,3 +699,4 @@ namespace Ink_Canvas.Windows.SettingsViews
}
}
}
+