add:新设置

This commit is contained in:
2026-01-11 00:16:22 +08:00
parent 17e6d23650
commit 1b2db81dde
2 changed files with 413 additions and 4 deletions
@@ -6,13 +6,169 @@
xmlns:local="clr-namespace:Ink_Canvas.Windows.SettingsViews"
mc:Ignorable="d"
d:DesignHeight="950" d:DesignWidth="640">
<UserControl.Resources>
<Style x:Key="ToggleSwitchStyle" TargetType="Border">
<Setter Property="Width" Value="48"/>
<Setter Property="Height" Value="25"/>
<Setter Property="CornerRadius" Value="12"/>
<Setter Property="Padding" Value="3,0"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Margin" Value="0,0,15,0"/>
</Style>
<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="IsTabStop" Value="false"/>
<EventSetter Event="PreviewMouseDown" Handler="ScrollbarThumb_MouseDown"/>
<EventSetter Event="PreviewMouseUp" Handler="ScrollbarThumb_MouseUp"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Name="ScrollbarThumbEx"
SnapsToDevicePixels="True"
Background="#c3c3c3"
Opacity="0.5"
CornerRadius="1.5"
Height="{TemplateBinding Height}"
Width="3" HorizontalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ScrollBar}">
<EventSetter Event="Scroll" Handler="ScrollBar_Scroll"/>
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="false"/>
<Setter Property="Width" Value="8"/>
<Setter Property="Margin" Value="-6 3 0 0" />
<Setter Property="MinWidth" Value="{Binding Height, RelativeSource={RelativeSource Self}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Grid x:Name="ScrollbarGrid" SnapsToDevicePixels="true">
<Border Width="3" CornerRadius="1.5" Background="#e0e0e0" Opacity="0" IsHitTestVisible="False" Margin="0 4 -2 4" x:Name="ScrollBarBorderTrackBackground"/>
<Border Padding="0 4" Background="Transparent" MouseEnter="ScrollBarTrack_MouseEnter"
MouseLeave="ScrollBarTrack_MouseLeave">
<Track x:Name="PART_Track"
IsDirectionReversed="true"
IsEnabled="True"
Width="6"
Margin="0,0,0,0"
HorizontalAlignment="Right">
<Track.DecreaseRepeatButton>
<RepeatButton Opacity="0" Command="{x:Static ScrollBar.PageUpCommand}" />
</Track.DecreaseRepeatButton>
<Track.IncreaseRepeatButton>
<RepeatButton Opacity="0" Command="{x:Static ScrollBar.PageDownCommand}" />
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb }" />
</Track.Thumb>
</Track>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<ScrollViewer ScrollChanged="ScrollViewerEx_ScrollChanged" IsManipulationEnabled="True" Name="UpdateCenterScrollViewerEx" IsDeferredScrollingEnabled="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" IsTabStop="False" TabIndex="-1" Margin="0,0,2,2">
<StackPanel Margin="0,12,0,24" HorizontalAlignment="Center" Width="524">
<TextBlock Foreground="#2e3436" FontSize="18" FontWeight="Bold" Text="更新中心" Margin="0,0,0,20"/>
<TextBlock Name="UpdateStatusText" Foreground="#878787" FontSize="14" Text="正在检查更新..." TextWrapping="Wrap" Margin="0,0,0,20"/>
<TextBlock Foreground="#2e3436" FontSize="24" FontWeight="Bold" Text="更新中心" Margin="0,0,0,8"/>
<TextBlock Foreground="#878787" FontSize="14" Text="检查并安装 InkCanvasForClass 的最新更新" TextWrapping="Wrap" Margin="0,0,0,24"/>
<Border BorderBrush="#e6e6e6" BorderThickness="1.25,1.25,1.25,4" CornerRadius="8" Padding="20" Margin="0,0,0,20">
<StackPanel>
<Grid Margin="0,0,0,16">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Foreground="#2e3436" FontSize="18" FontWeight="SemiBold" Text="当前版本" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock Name="CurrentVersionText" Foreground="#878787" FontSize="16" Text="正在获取..." VerticalAlignment="Center"/>
</StackPanel>
</Grid>
<Border Height="1" Background="#ebebeb" Margin="0,0,0,16"/>
<Grid Margin="0,0,0,16">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Foreground="#2e3436" FontSize="18" FontWeight="SemiBold" Text="更新状态" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock Name="UpdateStatusText" Foreground="#878787" FontSize="16" Text="正在检查更新..." VerticalAlignment="Center"/>
<Image Name="UpdateStatusIcon" Margin="8,0,0,0" Width="20" Height="20" VerticalAlignment="Center" Visibility="Collapsed">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup ClipGeometry="M0,0 V16 H16 V0 H0 Z">
<GeometryDrawing Brush="#FFFF7800" Geometry="F1 M16,16z M0,0z M8.00493,0C7.74518,0,7.49541,0.0999063,7.2956,0.289728L5.5872,1.99813 2.99963,1.99813C2.45014,1.99813,2.00056,2.44771,2.00056,2.99719L2.00056,5.58476 0.292165,7.29316C-0.0974697,7.6828,-0.0974697,8.31221,0.292165,8.70184L2.00056,10.4102 2.00056,12.9978C2.00056,13.5473,2.45014,13.9969,2.99963,13.9969L5.5872,13.9969 7.2956,15.7053C7.68523,16.0949,8.31464,16.0949,8.70428,15.7053L10.4127,13.9969 13.0003,13.9969C13.5497,13.9969,13.9993,13.5473,13.9993,12.9978L13.9993,10.4102 15.7077,8.70184C16.0973,8.31221,16.0973,7.6828,15.7077,7.29316L13.9993,5.58476 13.9993,2.99719C13.9993,2.44771,13.5497,1.99813,13.0003,1.99813L10.4127,1.99813 8.70428,0.289728C8.50447,0.0899157,8.2547,0,7.99494,0L8.00493,0z M8.00493,4.99532C8.26469,4.99532,8.51446,5.09522,8.71427,5.28505L10.7124,7.28317C10.9022,7.47299,11.0021,7.72276,11.0021,7.99251L11.0021,8.99157 9.004,8.99157 9.004,10.9897 7.00587,10.9897 7.00587,8.99157 5.00774,8.99157 5.00774,7.99251C5.00774,7.73275,5.10765,7.47299,5.29747,7.28317L7.2956,5.28505C7.49541,5.08523,7.74518,4.99532,8.00493,4.99532z" />
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</StackPanel>
</Grid>
<Border Height="1" Background="#ebebeb" Margin="0,0,0,16"/>
<StackPanel Name="UpdateAvailablePanel" Visibility="Collapsed">
<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="16,8" FontSize="14" Cursor="Hand" Click="UpdateNowButton_Click" Background="#0078D4" Foreground="White" BorderThickness="0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" CornerRadius="4" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<Button Name="CheckUpdateButton" Content="检查更新" HorizontalAlignment="Left" Padding="16,8" FontSize="14" Cursor="Hand" Click="CheckUpdateButton_Click" Background="#F3F3F3" Foreground="#2e3436" BorderThickness="1" BorderBrush="#E1E1E1" Margin="0,8,0,0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
</Border>
<Border BorderBrush="#e6e6e6" BorderThickness="1.25,1.25,1.25,4" CornerRadius="8" Padding="20">
<StackPanel>
<TextBlock Foreground="#2e3436" FontSize="18" FontWeight="SemiBold" Text="更新设置" Margin="0,0,0,16"/>
<Grid Height="54">
<TextBlock Foreground="#2e3436" FontSize="14.5" Text="自动检查更新" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<Border Name="AutoUpdateToggle" Style="{StaticResource ToggleSwitchStyle}" Background="#e1e1e1" Tag="AutoUpdate" MouseLeftButtonDown="ToggleSwitch_Click" HorizontalAlignment="Right" VerticalAlignment="Center">
<Border Width="19" Height="19" Background="White" CornerRadius="10" HorizontalAlignment="Left" VerticalAlignment="Center">
<Border.Effect>
<DropShadowEffect BlurRadius="4" Direction="-45" Color="Black" Opacity="0.3" ShadowDepth="0"/>
</Border.Effect>
</Border>
</Border>
</Grid>
<TextBlock Foreground="#878787" FontSize="12" Text="启用后,应用将在启动时自动检查更新" TextWrapping="Wrap" Margin="0,4,0,16"/>
<Border Height="1" Background="#ebebeb" Margin="0,0,0,16"/>
<Grid Height="54">
<TextBlock Foreground="#2e3436" FontSize="14.5" Text="更新通道" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<ComboBox Name="UpdateChannelComboBox" HorizontalAlignment="Right" VerticalAlignment="Center" Width="150" SelectionChanged="UpdateChannelComboBox_SelectionChanged">
<ComboBoxItem Content="稳定版" Tag="Release"/>
<ComboBoxItem Content="测试版" Tag="Beta"/>
</ComboBox>
</Grid>
<TextBlock Foreground="#878787" FontSize="12" Text="选择要接收的更新类型" TextWrapping="Wrap" Margin="0,4,0,0"/>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>
@@ -1,15 +1,218 @@
using iNKORE.UI.WPF.Helpers;
using Ink_Canvas.Helpers;
using System;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
namespace Ink_Canvas.Windows.SettingsViews
{
public partial class UpdateCenterPanel : UserControl
{
private bool isLoaded = false;
public UpdateCenterPanel()
{
InitializeComponent();
Loaded += UpdateCenterPanel_Loaded;
}
private void UpdateCenterPanel_Loaded(object sender, RoutedEventArgs e)
{
if (!isLoaded)
{
isLoaded = true;
LoadSettings();
CheckUpdateStatus();
}
}
private void LoadSettings()
{
try
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
CurrentVersionText.Text = $"InkCanvasForClass v{version}";
if (MainWindow.Settings?.Startup != null)
{
UpdateToggleSwitch(AutoUpdateToggle, MainWindow.Settings.Startup.IsAutoUpdate);
if (UpdateChannelComboBox != null)
{
foreach (ComboBoxItem item in UpdateChannelComboBox.Items)
{
if (item.Tag?.ToString() == MainWindow.Settings.Startup.UpdateChannel.ToString())
{
UpdateChannelComboBox.SelectedItem = item;
break;
}
}
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"UpdateCenterPanel 加载设置失败: {ex.Message}");
}
}
private void UpdateToggleSwitch(Border toggle, bool isOn)
{
if (toggle == null) return;
toggle.Background = isOn ? new SolidColorBrush(Color.FromRgb(53, 132, 228)) : new SolidColorBrush(Color.FromRgb(225, 225, 225));
var innerBorder = toggle.Child as Border;
if (innerBorder != null)
{
innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left;
}
else
{
var ellipse = new Border
{
Width = 19,
Height = 19,
Background = Brushes.White,
CornerRadius = new CornerRadius(10),
HorizontalAlignment = isOn ? HorizontalAlignment.Right : HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center
};
ellipse.Effect = new System.Windows.Media.Effects.DropShadowEffect
{
BlurRadius = 4,
Direction = -45,
Color = Colors.Black,
Opacity = 0.3,
ShadowDepth = 0
};
toggle.Child = ellipse;
}
}
private void ToggleSwitch_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
var toggle = sender as Border;
if (toggle == null) return;
var tag = toggle.Tag?.ToString();
if (tag == "AutoUpdate" && MainWindow.Settings?.Startup != null)
{
MainWindowSettingsHelper.UpdateSettingSafely(() =>
{
MainWindow.Settings.Startup.IsAutoUpdate = !MainWindow.Settings.Startup.IsAutoUpdate;
UpdateToggleSwitch(toggle, MainWindow.Settings.Startup.IsAutoUpdate);
}, "ToggleSwitchIsAutoUpdate_Toggled", "ToggleSwitchIsAutoUpdate");
}
}
private void CheckUpdateButton_Click(object sender, RoutedEventArgs e)
{
CheckUpdateStatus();
}
private void UpdateNowButton_Click(object sender, RoutedEventArgs e)
{
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);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"立即更新失败: {ex.Message}");
}
}
private void UpdateChannelComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!isLoaded || MainWindow.Settings?.Startup == null) return;
var comboBox = sender as ComboBox;
if (comboBox?.SelectedItem is ComboBoxItem selectedItem)
{
var channel = selectedItem.Tag?.ToString();
if (Enum.TryParse<UpdateChannel>(channel, out var updateChannel))
{
MainWindowSettingsHelper.UpdateSettingSafely(() =>
{
MainWindow.Settings.Startup.UpdateChannel = updateChannel;
}, "UpdateChannelSelector_Checked");
}
}
}
private void CheckUpdateStatus()
{
UpdateStatusText.Text = "正在检查更新...";
UpdateStatusIcon.Visibility = Visibility.Collapsed;
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
CheckUpdateButton.IsEnabled = false;
Task.Run(async () =>
{
try
{
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)
{
var availableVersion = field.GetValue(mainWindow) as string;
Dispatcher.BeginInvoke(new Action(() =>
{
if (!string.IsNullOrEmpty(availableVersion))
{
UpdateStatusText.Text = "有可用更新";
UpdateStatusIcon.Visibility = Visibility.Visible;
LatestVersionText.Text = $"版本 {availableVersion} 现已可用";
UpdateAvailablePanel.Visibility = Visibility.Visible;
}
else
{
UpdateStatusText.Text = "已是最新版本";
UpdateStatusIcon.Visibility = Visibility.Collapsed;
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
}
CheckUpdateButton.IsEnabled = true;
}));
}
else
{
Dispatcher.BeginInvoke(new Action(() =>
{
UpdateStatusText.Text = "检查更新失败";
UpdateStatusIcon.Visibility = Visibility.Collapsed;
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
CheckUpdateButton.IsEnabled = true;
}));
}
}
}
catch (Exception ex)
{
Dispatcher.BeginInvoke(new Action(() =>
{
UpdateStatusText.Text = "检查更新失败";
UpdateStatusIcon.Visibility = Visibility.Collapsed;
UpdateAvailablePanel.Visibility = Visibility.Collapsed;
CheckUpdateButton.IsEnabled = true;
}));
System.Diagnostics.Debug.WriteLine($"检查更新状态失败: {ex.Message}");
}
});
}
public event EventHandler<RoutedEventArgs> IsTopBarNeedShadowEffect;
@@ -28,6 +231,57 @@ namespace Ink_Canvas.Windows.SettingsViews
}
}
private void ScrollBar_Scroll(object sender, RoutedEventArgs e)
{
var scrollbar = (ScrollBar)sender;
var scrollviewer = scrollbar.FindAscendant<ScrollViewer>();
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<ScrollBar>();
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<ScrollBar>();
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
@@ -41,4 +295,3 @@ namespace Ink_Canvas.Windows.SettingsViews
}
}
}