Files
ThreadPilot/Views/SystemTweaksView.xaml
T
PrimeBuild-pc 9bcafc5025 fix: detect the tweaks that are there, and let the buttons be read
Three cards showed a red line instead of a state. Two of them, Ethernet power
saving and interrupt moderation, scanned every network adapter subkey without
guarding the reads: one adapter the user cannot open - VPN and vendor virtual
adapters ship with tighter ACLs - threw out of the whole scan, so the tweak
declared itself unavailable even though every real Ethernet adapter was
readable. The unreadable key is now skipped on its own.

Memory Integrity read only CI\State, which several builds leave empty. It now
reads DeviceGuard\Scenarios first, where the running HVCI state actually
lives, and keeps CI\State as the fallback.

The message those failures produced was the raw framework string, "Requested
registry access is not allowed." - true, unactionable, and not something a
user should ever be shown. The exception goes to the log; the card gets a
sentence.

The buttons on that page were near-white text on near-white chrome in dark
theme: an inline Style with no BasedOn discards WPF-UI's implicit Button
style, so they fell back to the stock WPF chrome while the foreground kept
inheriting the dark theme. It was the only such style in the repo.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 23:38:13 +02:00

254 lines
15 KiB
XML

<UserControl x:Class="ThreadPilot.Views.SystemTweaksView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="800">
<UserControl.Resources>
<!-- Larger, labelled pill toggle. The native ui:ToggleSwitch is 40x20 with no text,
which reads as a decoration rather than a switch on this dense list. -->
<Style x:Key="PillToggleButtonStyle" TargetType="ToggleButton">
<Setter Property="MinWidth" Value="56"/>
<Setter Property="Height" Value="28"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border x:Name="Track"
Background="{DynamicResource ControlFillColorSecondaryBrush}"
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
BorderThickness="1"
CornerRadius="14"
Padding="3"
SnapsToDevicePixels="True">
<!-- Thumb and label are docked, never stacked, so a long localized
label (ru "ВЫКЛ") pushes the pill wider instead of colliding with
the thumb. MinWidth keeps the common case at the intended size. -->
<DockPanel LastChildFill="True">
<Ellipse x:Name="Thumb"
DockPanel.Dock="Left"
Width="20"
Height="20"
Fill="{DynamicResource TextSecondaryBrush}"/>
<TextBlock x:Name="StateLabel"
Text="{DynamicResource SystemTweaks_ToggleOff}"
FontSize="10"
FontWeight="SemiBold"
VerticalAlignment="Center"
TextAlignment="Center"
Margin="3,0,4,0"
Foreground="{DynamicResource TextSecondaryBrush}"/>
</DockPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Track" Property="Background" Value="{DynamicResource AccentFillColorDefaultBrush}"/>
<Setter TargetName="Track" Property="BorderBrush" Value="{DynamicResource AccentFillColorDefaultBrush}"/>
<Setter TargetName="Thumb" Property="DockPanel.Dock" Value="Right"/>
<Setter TargetName="Thumb" Property="Fill" Value="{DynamicResource TextOnAccentFillColorPrimaryBrush}"/>
<Setter TargetName="StateLabel" Property="Text" Value="{DynamicResource SystemTweaks_ToggleOn}"/>
<Setter TargetName="StateLabel" Property="Margin" Value="4,0,3,0"/>
<Setter TargetName="StateLabel" Property="Foreground" Value="{DynamicResource TextOnAccentFillColorPrimaryBrush}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Track" Property="BorderBrush" Value="{DynamicResource SoftSelectionBorderBrush}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Track" Property="Background" Value="{DynamicResource ControlFillColorDisabledBrush}"/>
<Setter TargetName="Track" Property="BorderBrush" Value="{DynamicResource BorderSubtleBrush}"/>
<Setter TargetName="Track" Property="Opacity" Value="0.6"/>
<Setter TargetName="Thumb" Property="Fill" Value="{DynamicResource TextSecondaryBrush}"/>
<Setter TargetName="StateLabel" Property="Foreground" Value="{DynamicResource TextSecondaryBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Header and Controls -->
<Border Grid.Row="0"
Style="{StaticResource StandardCardStyle}"
Margin="0,0,0,16">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- Description and Refresh Button -->
<Grid Grid.Row="0" Margin="0,10,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Text="{DynamicResource SystemTweaksView_Title}"
Style="{StaticResource PageTitleTextStyle}"
Margin="0,0,0,4"/>
<TextBlock Text="{DynamicResource SystemTweaksView_Subtitle}"
Style="{StaticResource PageSubtitleTextStyle}"/>
</StackPanel>
<Button Grid.Column="1"
Content="{DynamicResource SystemTweaksView_RefreshAll}"
Command="{Binding RefreshAllTweaksCommand}"
Padding="12,6"
ToolTip="{DynamicResource SystemTweaksView_RefreshAllTooltip}"
IsEnabled="{Binding IsRefreshing, Converter={StaticResource InverseBooleanConverter}}"/>
</Grid>
<!-- Status Bar -->
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="{DynamicResource SystemTweaksView_Status}"
FontWeight="SemiBold"
VerticalAlignment="Center"/>
<TextBlock Grid.Column="1"
Text="{Binding RefreshStatusText}"
Foreground="{DynamicResource TextSecondaryBrush}"
Margin="10,0"
VerticalAlignment="Center"/>
<ProgressBar Grid.Column="2"
Width="100"
Height="4"
IsIndeterminate="{Binding IsRefreshing}"
Visibility="{Binding IsRefreshing, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Grid>
</Grid>
</Border>
<!-- Tweaks List -->
<ScrollViewer Grid.Row="1"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled">
<ItemsControl ItemsSource="{Binding TweakItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<GroupBox Margin="0,0,12,12" Padding="{DynamicResource CompactCardPadding}">
<GroupBox.Header>
<TextBlock Text="{Binding Name}"
FontSize="14"
FontWeight="SemiBold"
Foreground="{DynamicResource TextPrimaryBrush}"/>
</GroupBox.Header>
<StackPanel>
<TextBlock Text="{Binding Description}"
FontSize="11"
Foreground="{DynamicResource TextSecondaryBrush}"
TextWrapping="Wrap"
Margin="0,0,0,8"/>
<Grid Margin="0,0,0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
<Ellipse Width="8" Height="8"
VerticalAlignment="Center"
Margin="0,0,8,0">
<Ellipse.Style>
<Style TargetType="Ellipse">
<Setter Property="Fill" Value="{DynamicResource SuccessTextBrush}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsAvailable}" Value="False">
<Setter Property="Fill" Value="{DynamicResource ErrorTextBrush}"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsEnabled}" Value="False">
<Setter Property="Fill" Value="{DynamicResource TextSecondaryBrush}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Ellipse.Style>
</Ellipse>
<TextBlock Text="{Binding StatusText}"
FontSize="11"
Foreground="{DynamicResource TextSecondaryBrush}"
VerticalAlignment="Center"/>
</StackPanel>
<ToggleButton Grid.Column="1"
IsChecked="{Binding IsEnabled, Mode=OneWay}"
IsEnabled="{Binding IsAvailable}"
Command="{Binding ToggleCommand}"
CommandParameter="{Binding}"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="10,0,0,0"
AutomationProperties.Name="{Binding Name}"
ToolTip="{DynamicResource SystemTweaksView_TweakTooltip}">
<ToggleButton.Style>
<Style TargetType="ToggleButton" BasedOn="{StaticResource PillToggleButtonStyle}">
<Setter Property="Visibility" Value="Visible"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsGuidedAction}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
<Button Grid.Column="1"
Content="{DynamicResource SystemTweaks_OpenSettings}"
Command="{Binding ActionCommand}"
CommandParameter="{Binding}"
IsEnabled="{Binding IsAvailable}"
Padding="10,4"
AutomationProperties.Name="{Binding Name}">
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsGuidedAction}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</Grid>
<TextBlock Text="{Binding ErrorMessage}"
FontSize="11"
Foreground="{DynamicResource ErrorTextBrush}"
TextWrapping="Wrap"
Visibility="{Binding ErrorMessage, Converter={StaticResource StringToVisibilityConverter}}"/>
</StackPanel>
</GroupBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</UserControl>