add:新设置

This commit is contained in:
2026-02-07 15:21:42 +08:00
parent e11e1989ad
commit 324d514f10
2 changed files with 247 additions and 13 deletions
@@ -70,15 +70,60 @@
<StackPanel>
<TextBlock Foreground="#2e3436" FontSize="16" FontWeight="SemiBold" Text="可用更新" Margin="0,0,0,8"/>
<TextBlock Name="LatestVersionText" Foreground="#878787" FontSize="14" Text="" TextWrapping="Wrap" Margin="0,0,0,16"/>
<Button Name="UpdateNowButton" Content="立即更新" HorizontalAlignment="Left" Padding="20,10" FontSize="14" Cursor="Hand" Click="UpdateNowButton_Click" Background="#0078D4" Foreground="White" BorderThickness="0">
<StackPanel Orientation="Vertical">
<Button Name="UpdateNowButton" Content="立即下载并安装" HorizontalAlignment="Left" Padding="20,10" FontSize="14" FontWeight="SemiBold" Cursor="Hand" Click="UpdateNowButton_Click" Background="#0078D4" Foreground="White" BorderThickness="0" MinWidth="200" Margin="0,0,0,12">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="4" Padding="{TemplateBinding Padding}">
<Border Background="{TemplateBinding Background}" CornerRadius="6" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#005a9e"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#004578"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
<Button Name="UpdateLaterButton" Content="下载并在软件关闭时安装" HorizontalAlignment="Left" Padding="20,10" FontSize="14" FontWeight="Medium" Cursor="Hand" Click="UpdateLaterButton_Click" Background="Transparent" Foreground="#2e3436" BorderThickness="1" BorderBrush="#e6e6e6" MinWidth="200" Margin="0,0,0,12">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6" Padding="{TemplateBinding Padding}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#f5f5f5"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#e8e8e8"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
<Button Name="SkipVersionButton" Content="跳过该版本" HorizontalAlignment="Left" Padding="20,10" FontSize="14" FontWeight="Medium" Cursor="Hand" Click="SkipVersionButton_Click" Background="Transparent" Foreground="#0078D4" BorderThickness="0" MinWidth="200">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="6" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#f5f5f5"/>
<Setter Property="Foreground" Value="#005a9e"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="#e8e8e8"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
</StackPanel>
</Border>
</StackPanel>
@@ -1,16 +1,16 @@
using iNKORE.UI.WPF.Helpers;
using iNKORE.UI.WPF.Modern;
using iNKORE.UI.WPF.Modern.Controls;
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.Media;
using MessageBox = System.Windows.MessageBox;
using static Ink_Canvas.Helpers.AutoUpdateHelper;
namespace Ink_Canvas.Windows.SettingsViews
{
@@ -19,6 +19,8 @@ namespace Ink_Canvas.Windows.SettingsViews
private bool _isLoaded = false;
private string _currentTab = "Update";
private List<(string version, string downloadUrl, string releaseNotes)> _historyVersions = new List<(string, string, string)>();
private string _availableVersion = null;
private UpdateLineGroup _availableLineGroup = null;
public UpdateCenterPanel()
{
@@ -216,15 +218,169 @@ namespace Ink_Canvas.Windows.SettingsViews
CheckUpdateStatus(true);
}
private void UpdateNowButton_Click(object sender, RoutedEventArgs e)
private async void UpdateNowButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(_availableVersion))
{
MessageBox.Show("没有可用的更新版本。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
try
{
MainWindowSettingsHelper.InvokeMainWindowMethod("ManualUpdateButton_Click", sender, e);
UpdateNowButton.IsEnabled = false;
UpdateLaterButton.IsEnabled = false;
SkipVersionButton.IsEnabled = false;
var updateChannel = UpdateChannel.Release;
if (MainWindow.Settings?.Startup != null)
{
updateChannel = MainWindow.Settings.Startup.UpdateChannel;
}
var groups = _availableLineGroup != null ? new List<UpdateLineGroup> { _availableLineGroup } : AutoUpdateHelper.ChannelLineGroups[updateChannel];
bool downloadSuccess = await AutoUpdateHelper.DownloadSetupFileWithFallback(_availableVersion, groups, (percent, text) =>
{
Dispatcher.BeginInvoke(new Action(() =>
{
System.Diagnostics.Debug.WriteLine($"下载进度: {percent}% - {text}");
}));
});
if (downloadSuccess)
{
AutoUpdateHelper.InstallNewVersionApp(_availableVersion, true);
App.IsAppExitByUser = true;
Application.Current.Dispatcher.Invoke(() =>
{
Application.Current.Shutdown();
});
}
else
{
MessageBox.Show("下载失败,请检查网络连接后重试。", "下载失败", MessageBoxButton.OK, MessageBoxImage.Error);
UpdateNowButton.IsEnabled = true;
UpdateLaterButton.IsEnabled = true;
SkipVersionButton.IsEnabled = true;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"立即更新失败: {ex.Message}");
MessageBox.Show($"更新过程中发生错误:{ex.Message}", "更新错误", MessageBoxButton.OK, MessageBoxImage.Error);
UpdateNowButton.IsEnabled = true;
UpdateLaterButton.IsEnabled = true;
SkipVersionButton.IsEnabled = true;
}
}
private async void UpdateLaterButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(_availableVersion))
{
MessageBox.Show("没有可用的更新版本。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
try
{
UpdateNowButton.IsEnabled = false;
UpdateLaterButton.IsEnabled = false;
SkipVersionButton.IsEnabled = false;
var updateChannel = UpdateChannel.Release;
if (MainWindow.Settings?.Startup != null)
{
updateChannel = MainWindow.Settings.Startup.UpdateChannel;
}
var groups = _availableLineGroup != null ? new List<AutoUpdateHelper.UpdateLineGroup> { _availableLineGroup } : AutoUpdateHelper.ChannelLineGroups[updateChannel];
bool downloadSuccess = await AutoUpdateHelper.DownloadSetupFileWithFallback(_availableVersion, groups, (percent, text) =>
{
Dispatcher.BeginInvoke(new Action(() =>
{
System.Diagnostics.Debug.WriteLine($"下载进度: {percent}% - {text}");
}));
});
if (downloadSuccess)
{
MainWindow.Settings.Startup.IsAutoUpdate = true;
MainWindow.Settings.Startup.IsAutoUpdateWithSilence = true;
MainWindow.SaveSettingsToFile();
var mainWindow = Application.Current.MainWindow as MainWindow;
if (mainWindow != null)
{
var field = typeof(MainWindow).GetField("AvailableLatestVersion", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (field != null)
{
field.SetValue(mainWindow, _availableVersion);
}
var timerField = typeof(MainWindow).GetField("timerCheckAutoUpdateWithSilence", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (timerField != null)
{
var timer = timerField.GetValue(mainWindow);
if (timer != null)
{
var startMethod = timer.GetType().GetMethod("Start");
if (startMethod != null)
{
startMethod.Invoke(timer, null);
}
}
}
}
MessageBox.Show("更新已下载完成,将在软件关闭时自动安装。", "更新已准备就绪", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
MessageBox.Show("下载失败,请检查网络连接后重试。", "下载失败", MessageBoxButton.OK, MessageBoxImage.Error);
}
UpdateNowButton.IsEnabled = true;
UpdateLaterButton.IsEnabled = true;
SkipVersionButton.IsEnabled = true;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"稍后更新失败: {ex.Message}");
MessageBox.Show($"更新过程中发生错误:{ex.Message}", "更新错误", MessageBoxButton.OK, MessageBoxImage.Error);
UpdateNowButton.IsEnabled = true;
UpdateLaterButton.IsEnabled = true;
SkipVersionButton.IsEnabled = true;
}
}
private void SkipVersionButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(_availableVersion))
{
MessageBox.Show("没有可用的更新版本。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
try
{
MainWindow.Settings.Startup.SkippedVersion = _availableVersion;
MainWindow.SaveSettingsToFile();
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
UpdateStatusText.Text = "已跳过该版本";
MessageBox.Show($"已设置跳过版本 {_availableVersion},在下次发布新版本之前不会再提示更新。",
"已跳过此版本",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"跳过版本失败: {ex.Message}");
MessageBox.Show($"跳过版本时发生错误:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
@@ -247,6 +403,19 @@ namespace Ink_Canvas.Windows.SettingsViews
var (remoteVersion, lineGroup, releaseNotes) = await AutoUpdateHelper.CheckForUpdates(updateChannel, manualCheck, false);
if (manualCheck)
{
var mainWindow = Application.Current.MainWindow as MainWindow;
if (mainWindow != null)
{
var field = typeof(MainWindow).GetField("AvailableLatestVersion", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (field != null)
{
field.SetValue(mainWindow, null);
}
}
}
Dispatcher.BeginInvoke(new Action(() =>
{
StopLoadingAnimation();
@@ -265,17 +434,23 @@ namespace Ink_Canvas.Windows.SettingsViews
UpdateStatusText.Text = "有可用更新";
LatestVersionText.Text = $"版本 {remoteVersion} 现已可用";
UpdateAvailablePanel.Visibility = Visibility.Visible;
_availableVersion = remoteVersion;
_availableLineGroup = lineGroup;
}
else
{
UpdateStatusText.Text = "你使用的是最新版本";
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
_availableVersion = null;
_availableLineGroup = null;
}
}
else
{
UpdateStatusText.Text = "你使用的是最新版本";
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
_availableVersion = null;
_availableLineGroup = null;
}
if (!string.IsNullOrEmpty(releaseNotes))
@@ -808,6 +983,20 @@ namespace Ink_Canvas.Windows.SettingsViews
UpdateNowButton.Foreground = Brushes.White;
}
if (UpdateLaterButton != null)
{
UpdateLaterButton.Background = ThemeHelper.GetButtonBackgroundBrush();
UpdateLaterButton.Foreground = ThemeHelper.GetTextPrimaryBrush();
UpdateLaterButton.BorderBrush = ThemeHelper.GetBorderPrimaryBrush();
}
if (SkipVersionButton != null)
{
SkipVersionButton.Background = Brushes.Transparent;
SkipVersionButton.Foreground = new SolidColorBrush(Color.FromRgb(0, 120, 212));
SkipVersionButton.BorderThickness = new Thickness(0);
}
if (RollbackButton != null)
{
RollbackButton.Background = ThemeHelper.GetButtonBackgroundBrush();