Files
community/Ink Canvas/Windows/SettingsViews/SettingsViews/UpdateCenterPanel.xaml.cs
T

703 lines
28 KiB
C#
Raw Normal View History

2026-01-10 23:20:31 +08:00
using iNKORE.UI.WPF.Helpers;
2026-01-11 00:16:22 +08:00
using Ink_Canvas.Helpers;
2026-01-10 23:20:31 +08:00
using System;
2026-02-07 14:49:52 +08:00
using System.Collections.Generic;
2026-01-11 08:23:09 +08:00
using System.IO;
2026-02-07 14:49:52 +08:00
using System.Linq;
2026-01-11 00:16:22 +08:00
using System.Reflection;
using System.Threading.Tasks;
2026-01-10 23:20:31 +08:00
using System.Windows;
using System.Windows.Controls;
2026-01-11 00:16:22 +08:00
using System.Windows.Media;
2026-01-10 23:20:31 +08:00
namespace Ink_Canvas.Windows.SettingsViews
{
public partial class UpdateCenterPanel : UserControl
{
2026-02-07 14:49:52 +08:00
private bool _isLoaded = false;
private string _currentTab = "Update";
private List<(string version, string downloadUrl, string releaseNotes)> _historyVersions = new List<(string, string, string)>();
2026-01-11 00:16:22 +08:00
2026-01-10 23:20:31 +08:00
public UpdateCenterPanel()
{
InitializeComponent();
2026-01-11 00:16:22 +08:00
Loaded += UpdateCenterPanel_Loaded;
}
private void UpdateCenterPanel_Loaded(object sender, RoutedEventArgs e)
{
2026-02-07 14:49:52 +08:00
if (!_isLoaded)
2026-01-11 00:16:22 +08:00
{
2026-02-07 14:49:52 +08:00
_isLoaded = true;
2026-01-11 00:16:22 +08:00
LoadSettings();
2026-02-07 14:49:52 +08:00
SwitchTab("Update");
2026-01-11 00:16:22 +08:00
CheckUpdateStatus();
2026-02-07 14:49:52 +08:00
LoadUpdateLog(MainWindow.Settings?.Startup?.UpdateChannel ?? UpdateChannel.Release);
2026-01-11 08:23:09 +08:00
ApplyTheme();
2026-01-11 00:16:22 +08:00
}
}
private void LoadSettings()
{
2026-02-07 14:49:52 +08:00
if (MainWindow.Settings == null) return;
2026-01-11 00:16:22 +08:00
try
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
2026-01-11 08:23:09 +08:00
var platform = Environment.Is64BitOperatingSystem ? "windows-x64" : "windows-x86";
CurrentVersionText.Text = $"当前版本: v{version} | {platform}";
2026-01-11 00:16:22 +08:00
2026-01-11 08:23:09 +08:00
LoadLastCheckTime();
2026-02-07 14:49:52 +08:00
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<ComboBoxItem>()
.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<ComboBoxItem>()
.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);
}
2026-01-11 00:16:22 +08:00
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"UpdateCenterPanel 加载设置失败: {ex.Message}");
}
}
2026-01-11 08:23:09 +08:00
private void LoadLastCheckTime()
2026-01-11 00:16:22 +08:00
{
2026-01-11 08:23:09 +08:00
try
2026-01-11 00:16:22 +08:00
{
2026-01-17 16:51:28 +08:00
var lastCheckTime = DeviceIdentifier.GetLastUpdateCheck();
if (lastCheckTime != DateTime.MinValue)
2026-01-11 08:23:09 +08:00
{
2026-01-17 16:51:28 +08:00
var now = DateTime.Now;
var timeDiff = now - lastCheckTime;
if (timeDiff.TotalDays < 1 && lastCheckTime.Date == now.Date)
2026-01-11 08:23:09 +08:00
{
2026-01-17 16:51:28 +08:00
LastCheckTimeText.Text = $"上次检查时间: 今天, {lastCheckTime:HH:mm}";
2026-01-11 08:23:09 +08:00
}
2026-01-17 16:51:28 +08:00
else if (timeDiff.TotalDays < 2 && lastCheckTime.Date == now.Date.AddDays(-1))
{
LastCheckTimeText.Text = $"上次检查时间: 昨天, {lastCheckTime:HH:mm}";
}
else
{
LastCheckTimeText.Text = $"上次检查时间: {lastCheckTime:yyyy-MM-dd HH:mm}";
}
return;
2026-01-11 08:23:09 +08:00
}
LastCheckTimeText.Text = "上次检查时间: 从未";
2026-01-11 00:16:22 +08:00
}
2026-01-11 08:23:09 +08:00
catch
2026-01-11 00:16:22 +08:00
{
2026-01-11 08:23:09 +08:00
LastCheckTimeText.Text = "上次检查时间: 从未";
2026-01-11 00:16:22 +08:00
}
}
2026-01-11 08:23:09 +08:00
private void SaveLastCheckTime()
2026-01-11 00:16:22 +08:00
{
2026-01-11 08:23:09 +08:00
try
2026-01-11 00:16:22 +08:00
{
2026-01-17 16:51:28 +08:00
DeviceIdentifier.RecordUpdateCheck();
2026-01-11 08:23:09 +08:00
LoadLastCheckTime();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"保存上次检查时间失败: {ex.Message}");
2026-01-11 00:16:22 +08:00
}
}
2026-02-07 14:49:52 +08:00
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();
}
}
2026-01-11 00:16:22 +08:00
private void CheckUpdateButton_Click(object sender, RoutedEventArgs e)
{
2026-01-11 08:23:09 +08:00
CheckUpdateStatus(true);
2026-01-11 00:16:22 +08:00
}
private void UpdateNowButton_Click(object sender, RoutedEventArgs e)
{
try
{
2026-02-07 14:49:52 +08:00
MainWindowSettingsHelper.InvokeMainWindowMethod("ManualUpdateButton_Click", sender, e);
2026-01-11 00:16:22 +08:00
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"立即更新失败: {ex.Message}");
}
}
2026-01-11 08:23:09 +08:00
private void CheckUpdateStatus(bool manualCheck = false)
2026-01-11 00:16:22 +08:00
{
UpdateStatusText.Text = "正在检查更新...";
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
CheckUpdateButton.IsEnabled = false;
2026-01-11 08:23:09 +08:00
StartLoadingAnimation();
2026-01-11 00:16:22 +08:00
Task.Run(async () =>
{
try
{
2026-01-11 08:23:09 +08:00
var updateChannel = UpdateChannel.Release;
if (MainWindow.Settings?.Startup != null)
{
updateChannel = MainWindow.Settings.Startup.UpdateChannel;
}
var (remoteVersion, lineGroup, releaseNotes) = await AutoUpdateHelper.CheckForUpdates(updateChannel, manualCheck, false);
Dispatcher.BeginInvoke(new Action(() =>
2026-01-11 00:16:22 +08:00
{
2026-01-11 08:23:09 +08:00
StopLoadingAnimation();
if (!string.IsNullOrEmpty(remoteVersion))
2026-01-11 00:16:22 +08:00
{
2026-01-11 08:23:09 +08:00
var localVersion = Assembly.GetExecutingAssembly().GetName().Version;
var localVersionStr = localVersion.ToString();
var remoteVersionStr = remoteVersion.TrimStart('v', 'V');
2026-01-11 00:16:22 +08:00
2026-01-11 08:23:09 +08:00
Version local = new Version(localVersionStr);
Version remote = new Version(remoteVersionStr);
if (remote > local)
{
UpdateStatusText.Text = "有可用更新";
LatestVersionText.Text = $"版本 {remoteVersion} 现已可用";
UpdateAvailablePanel.Visibility = Visibility.Visible;
}
else
2026-01-11 00:16:22 +08:00
{
2026-01-11 08:23:09 +08:00
UpdateStatusText.Text = "你使用的是最新版本";
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
}
2026-01-11 00:16:22 +08:00
}
else
{
2026-01-11 08:23:09 +08:00
UpdateStatusText.Text = "你使用的是最新版本";
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
2026-01-11 00:16:22 +08:00
}
2026-02-07 14:49:52 +08:00
if (!string.IsNullOrEmpty(releaseNotes))
{
UpdateLogViewer.Markdown = releaseNotes;
}
else
{
LoadUpdateLog(updateChannel);
}
2026-01-11 08:23:09 +08:00
if (manualCheck)
{
SaveLastCheckTime();
}
CheckUpdateButton.IsEnabled = true;
}));
2026-01-11 00:16:22 +08:00
}
catch (Exception ex)
{
Dispatcher.BeginInvoke(new Action(() =>
{
2026-01-11 08:23:09 +08:00
StopLoadingAnimation();
2026-01-11 00:16:22 +08:00
UpdateStatusText.Text = "检查更新失败";
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
CheckUpdateButton.IsEnabled = true;
}));
System.Diagnostics.Debug.WriteLine($"检查更新状态失败: {ex.Message}");
}
});
2026-01-10 23:20:31 +08:00
}
2026-02-07 14:49:52 +08:00
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 = "加载更新日志失败";
}
}
2026-01-10 23:20:31 +08:00
2026-02-07 14:49:52 +08:00
private async void LoadHistoryVersions()
2026-01-10 23:20:31 +08:00
{
2026-02-07 14:49:52 +08:00
try
2026-01-10 23:20:31 +08:00
{
2026-02-07 14:49:52 +08:00
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 = "未获取到历史版本信息。";
}
2026-01-10 23:20:31 +08:00
}
2026-02-07 14:49:52 +08:00
catch (Exception ex)
2026-01-10 23:20:31 +08:00
{
2026-02-07 14:49:52 +08:00
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;
2026-01-10 23:20:31 +08:00
}
}
2026-02-07 14:49:52 +08:00
private void UpdateUpdateChannelButtons(UpdateChannel selectedChannel)
2026-01-11 00:16:22 +08:00
{
2026-02-07 14:49:52 +08:00
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}");
}
2026-01-11 00:16:22 +08:00
}
2026-02-07 14:49:52 +08:00
private void ToggleSwitch_Click(object sender, RoutedEventArgs e)
2026-01-11 00:16:22 +08:00
{
2026-02-07 14:49:52 +08:00
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)
2026-01-11 00:16:22 +08:00
{
2026-02-07 14:49:52 +08:00
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;
2026-01-11 00:16:22 +08:00
}
}
2026-02-07 14:49:52 +08:00
private bool GetCurrentSettingValue(string tag)
2026-01-11 00:16:22 +08:00
{
2026-02-07 14:49:52 +08:00
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
2026-01-11 00:16:22 +08:00
{
2026-02-07 14:49:52 +08:00
return false;
2026-01-11 00:16:22 +08:00
}
}
2026-02-07 14:49:52 +08:00
private Border FindToggleSwitch(string name)
{
return this.FindDescendantByName(name) as Border;
}
private void SetToggleSwitchState(Border toggleSwitch, bool isOn)
2026-01-11 00:16:22 +08:00
{
2026-02-07 14:49:52 +08:00
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)
2026-01-11 00:16:22 +08:00
{
2026-02-07 14:49:52 +08:00
innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
innerBorder.Background = new SolidColorBrush(Colors.White);
2026-01-11 00:16:22 +08:00
}
}
2026-02-07 14:49:52 +08:00
private void AutoUpdateWithSilenceStartTimeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
2026-01-11 00:16:22 +08:00
{
2026-02-07 14:49:52 +08:00
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<RoutedEventArgs> IsTopBarNeedShadowEffect;
public event EventHandler<RoutedEventArgs> IsTopBarNeedNoShadowEffect;
private void ScrollViewerEx_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
var scrollViewer = (ScrollViewer)sender;
if (scrollViewer.VerticalOffset >= 10)
2026-01-11 00:16:22 +08:00
{
2026-02-07 14:49:52 +08:00
IsTopBarNeedShadowEffect?.Invoke(this, new RoutedEventArgs());
}
else
{
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
2026-01-11 00:16:22 +08:00
}
}
2026-01-10 23:20:31 +08:00
public void ApplyTheme()
{
try
{
ThemeHelper.ApplyThemeToControl(this);
2026-01-11 08:23:09 +08:00
if (CheckUpdateButton != null)
{
CheckUpdateButton.Background = ThemeHelper.GetButtonBackgroundBrush();
CheckUpdateButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
CheckUpdateButton.BorderBrush = ThemeHelper.GetBorderPrimaryBrush();
}
if (UpdateNowButton != null)
{
UpdateNowButton.Background = new SolidColorBrush(Color.FromRgb(0, 120, 212));
UpdateNowButton.Foreground = Brushes.White;
}
2026-02-07 14:49:52 +08:00
if (RollbackButton != null)
{
RollbackButton.Background = ThemeHelper.GetButtonBackgroundBrush();
RollbackButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
}
if (FixVersionButton != null)
{
FixVersionButton.Background = ThemeHelper.GetButtonBackgroundBrush();
FixVersionButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
}
SwitchTab(_currentTab);
2026-01-10 23:20:31 +08:00
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"UpdateCenterPanel 应用主题时出错: {ex.Message}");
}
}
2026-01-11 08:23:09 +08:00
private void StartLoadingAnimation()
{
try
{
if (LoadingSpinner != null)
{
LoadingSpinner.IsActive = true;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"启动加载动画失败: {ex.Message}");
}
}
private void StopLoadingAnimation()
{
try
{
if (LoadingSpinner != null)
{
LoadingSpinner.IsActive = false;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"停止加载动画失败: {ex.Message}");
}
}
2026-01-10 23:20:31 +08:00
}
}
2026-02-07 14:49:52 +08:00