4fceda163d
* Improve background refresh and process detection * Harden affinity and power plan automation * Fix passive process refresh failures * Improve UX terminology and process layout * Polish UX layout and empty states * Expand core service test coverage
405 lines
25 KiB
XML
405 lines
25 KiB
XML
<UserControl x:Class="ThreadPilot.Views.ProcessPowerPlanAssociationView"
|
|
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:converters="clr-namespace:ThreadPilot.Converters"
|
|
xmlns:local="clr-namespace:ThreadPilot.Views"
|
|
mc:Ignorable="d"
|
|
d:DesignHeight="800" d:DesignWidth="1200">
|
|
|
|
<UserControl.Resources>
|
|
<converters:BoolToColorConverter x:Key="BoolToColorConverter"/>
|
|
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
|
|
<converters:InverseBooleanConverter x:Key="InverseBoolConverter"/>
|
|
</UserControl.Resources>
|
|
<Grid Margin="10">
|
|
<Grid.RowDefinitions>
|
|
<RowDefinition Height="Auto"/>
|
|
<RowDefinition Height="*"/>
|
|
</Grid.RowDefinitions>
|
|
|
|
<!-- Standardized Header -->
|
|
<GroupBox Grid.Row="0" Header="Rules & Automation" Margin="0,0,0,10">
|
|
<Grid Margin="5">
|
|
<TextBlock Text="Define per-process rules. Power plans are global; masks and priorities apply to matching processes."
|
|
FontSize="12" Foreground="{DynamicResource TextSecondaryBrush}" VerticalAlignment="Center"/>
|
|
</Grid>
|
|
</GroupBox>
|
|
|
|
<!-- Main Content -->
|
|
<TabControl Grid.Row="1" Background="{DynamicResource SurfaceBrush}" BorderThickness="0">
|
|
<TabControl.Resources>
|
|
<Style TargetType="TabItem">
|
|
<Setter Property="Padding" Value="14,7"/>
|
|
<Setter Property="Margin" Value="0,0,8,0"/>
|
|
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>
|
|
<Setter Property="Template">
|
|
<Setter.Value>
|
|
<ControlTemplate TargetType="TabItem">
|
|
<Border x:Name="TabBorder"
|
|
Background="{DynamicResource ControlFillColorSecondaryBrush}"
|
|
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
|
|
BorderThickness="1"
|
|
CornerRadius="8"
|
|
Padding="{TemplateBinding Padding}"
|
|
Margin="{TemplateBinding Margin}">
|
|
<ContentPresenter ContentSource="Header"
|
|
HorizontalAlignment="Center"
|
|
VerticalAlignment="Center"
|
|
TextElement.Foreground="{TemplateBinding Foreground}"/>
|
|
</Border>
|
|
<ControlTemplate.Triggers>
|
|
<Trigger Property="IsSelected" Value="True">
|
|
<Setter TargetName="TabBorder" Property="Background" Value="{DynamicResource SoftSelectionBackgroundBrush}"/>
|
|
<Setter TargetName="TabBorder" Property="BorderBrush" Value="{DynamicResource SoftSelectionBorderBrush}"/>
|
|
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>
|
|
<Setter TargetName="TabBorder" Property="Effect">
|
|
<Setter.Value>
|
|
<DropShadowEffect BlurRadius="10" ShadowDepth="1" Opacity="0.2"/>
|
|
</Setter.Value>
|
|
</Setter>
|
|
</Trigger>
|
|
</ControlTemplate.Triggers>
|
|
</ControlTemplate>
|
|
</Setter.Value>
|
|
</Setter>
|
|
</Style>
|
|
</TabControl.Resources>
|
|
|
|
<!-- Rules Tab -->
|
|
<TabItem Header="Rules">
|
|
<Grid Margin="10">
|
|
<Grid.ColumnDefinitions>
|
|
<ColumnDefinition Width="2*"/>
|
|
<ColumnDefinition Width="10"/>
|
|
<ColumnDefinition Width="*"/>
|
|
</Grid.ColumnDefinitions>
|
|
|
|
<!-- Rules List -->
|
|
<GroupBox Grid.Column="0" Header="Current Rules">
|
|
<Grid>
|
|
<Grid.RowDefinitions>
|
|
<RowDefinition Height="*"/>
|
|
<RowDefinition Height="Auto"/>
|
|
</Grid.RowDefinitions>
|
|
|
|
<DataGrid Grid.Row="0"
|
|
ItemsSource="{Binding Associations}"
|
|
SelectedItem="{Binding SelectedAssociation}"
|
|
AutoGenerateColumns="False"
|
|
CanUserAddRows="False"
|
|
GridLinesVisibility="Horizontal"
|
|
HeadersVisibility="Column"
|
|
BorderThickness="1">
|
|
<DataGrid.Columns>
|
|
<DataGridCheckBoxColumn Header="Enabled"
|
|
Binding="{Binding IsEnabled}"
|
|
Width="60"/>
|
|
<DataGridTextColumn Header="Executable"
|
|
Binding="{Binding ExecutableName}"
|
|
Width="150"/>
|
|
<DataGridTextColumn Header="Power Plan"
|
|
Binding="{Binding PowerPlanName}"
|
|
Width="120"/>
|
|
<DataGridTextColumn Header="CPU Mask"
|
|
Binding="{Binding CoreMaskName}"
|
|
Width="100"/>
|
|
<DataGridTextColumn Header="Priority"
|
|
Binding="{Binding ProcessPriority}"
|
|
Width="80"/>
|
|
<DataGridTextColumn Header="Rule Priority"
|
|
Binding="{Binding Priority}"
|
|
Width="60"/>
|
|
<DataGridCheckBoxColumn Header="Match by Path"
|
|
Binding="{Binding MatchByPath}"
|
|
Width="100"/>
|
|
<DataGridTextColumn Header="Description"
|
|
Binding="{Binding Description}"
|
|
Width="*"/>
|
|
</DataGrid.Columns>
|
|
</DataGrid>
|
|
|
|
<Border Grid.Row="0"
|
|
Padding="18"
|
|
IsHitTestVisible="False"
|
|
HorizontalAlignment="Center"
|
|
VerticalAlignment="Center">
|
|
<Border.Style>
|
|
<Style TargetType="Border">
|
|
<Setter Property="Visibility" Value="Collapsed"/>
|
|
<Style.Triggers>
|
|
<DataTrigger Binding="{Binding Associations.Count}" Value="0">
|
|
<Setter Property="Visibility" Value="Visible"/>
|
|
</DataTrigger>
|
|
</Style.Triggers>
|
|
</Style>
|
|
</Border.Style>
|
|
<StackPanel>
|
|
<TextBlock Text="No automation rules yet"
|
|
FontWeight="SemiBold"
|
|
HorizontalAlignment="Center"
|
|
Margin="0,0,0,4"/>
|
|
<TextBlock Text="Create a rule from an executable or running process to automate power plan, CPU mask, and priority behavior."
|
|
Foreground="{DynamicResource TextSecondaryBrush}"
|
|
TextWrapping="Wrap"
|
|
TextAlignment="Center"
|
|
MaxWidth="360"/>
|
|
</StackPanel>
|
|
</Border>
|
|
|
|
<StackPanel Grid.Row="1" Orientation="Horizontal"
|
|
HorizontalAlignment="Right" Margin="0,10,0,0">
|
|
<Button Content="Update"
|
|
Command="{Binding UpdateAssociationCommand}"
|
|
Margin="0,0,5,0" Padding="10,5"
|
|
ToolTip="Update the selected association"/>
|
|
<Button Content="Remove"
|
|
Command="{Binding RemoveAssociationCommand}"
|
|
Padding="10,5"
|
|
ToolTip="Remove the selected association"/>
|
|
</StackPanel>
|
|
</Grid>
|
|
</GroupBox>
|
|
|
|
<!-- Rule Editor -->
|
|
<GroupBox Grid.Column="2" Header="Rule Editor">
|
|
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
|
<StackPanel>
|
|
<!-- Executable Selection Section -->
|
|
<TextBlock Text="Executable Match:" FontWeight="Bold" Margin="0,0,0,5"/>
|
|
<TextBlock Text="Choose an executable. Match by path is more precise; matching by name applies to any process with that executable name."
|
|
Foreground="{DynamicResource TextSecondaryBrush}"
|
|
FontSize="10"
|
|
TextWrapping="Wrap"
|
|
Margin="0,0,0,8"/>
|
|
|
|
<!-- Browse Button -->
|
|
<Button Content="Browse for Executable"
|
|
Command="{Binding BrowseExecutableCommand}"
|
|
Padding="10,8" Margin="0,0,0,10"
|
|
HorizontalAlignment="Left"
|
|
ToolTip="Click to select an executable file (.exe) from your computer"/>
|
|
|
|
<!-- Selected Executable Display -->
|
|
<Border BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1"
|
|
Background="{DynamicResource SurfaceAltBrush}" Padding="8" Margin="0,0,0,10"
|
|
Visibility="{Binding HasSelectedExecutable, Converter={StaticResource BoolToVisibilityConverter}}">
|
|
<StackPanel>
|
|
<TextBlock Text="Selected Executable:" FontSize="10" Foreground="{DynamicResource TextSecondaryBrush}" Margin="0,0,0,2"/>
|
|
<TextBlock Text="{Binding SelectedExecutableDisplayName}"
|
|
FontWeight="Bold" Margin="0,0,0,2"/>
|
|
<TextBlock Text="{Binding SelectedExecutableFullPath}"
|
|
FontSize="10" Foreground="{DynamicResource TextSecondaryBrush}" TextWrapping="Wrap"/>
|
|
</StackPanel>
|
|
</Border>
|
|
|
|
<!-- Clear Selection Button -->
|
|
<Button Content="Clear Selection"
|
|
Command="{Binding ClearSelectedExecutableCommand}"
|
|
Padding="5,3" Margin="0,0,0,15"
|
|
HorizontalAlignment="Left" FontSize="10"
|
|
Visibility="{Binding HasSelectedExecutable, Converter={StaticResource BoolToVisibilityConverter}}"
|
|
ToolTip="Clear the selected executable"/>
|
|
|
|
<CheckBox Content="Match by Path"
|
|
IsChecked="{Binding MatchByPath}"
|
|
Margin="0,0,0,10"
|
|
ToolTip="Match processes by full path instead of just executable name"/>
|
|
|
|
<TextBlock Text="Rule Power Plan (global switch):" Margin="0,0,0,5" FontWeight="SemiBold"/>
|
|
<TextBlock Text="When this rule matches, Windows switches the global active power plan."
|
|
Foreground="{DynamicResource WarningTextBrush}"
|
|
FontSize="10"
|
|
TextWrapping="Wrap"
|
|
Margin="0,0,0,5"/>
|
|
<ComboBox ItemsSource="{Binding AvailablePowerPlans}"
|
|
SelectedItem="{Binding SelectedPowerPlan}"
|
|
DisplayMemberPath="Name"
|
|
Padding="5" Margin="0,0,0,10"/>
|
|
|
|
<TextBlock Text="Rule CPU Mask:" Margin="0,0,0,5"/>
|
|
<TextBlock Text="Applied only to matching processes; it does not change the global Windows power plan."
|
|
Foreground="{DynamicResource TextSecondaryBrush}"
|
|
FontSize="10"
|
|
TextWrapping="Wrap"
|
|
Margin="0,0,0,5"/>
|
|
<ComboBox ItemsSource="{Binding AvailableCoreMasks}"
|
|
SelectedItem="{Binding SelectedCoreMask}"
|
|
DisplayMemberPath="Name"
|
|
Padding="5" Margin="0,0,0,10"
|
|
ToolTip="Optional: Select a CPU mask to apply when this process starts"/>
|
|
|
|
<TextBlock Text="Process Priority:" Margin="0,0,0,5"/>
|
|
<TextBlock Text="Applied to each matching process when the automation rule runs."
|
|
Foreground="{DynamicResource TextSecondaryBrush}"
|
|
FontSize="10"
|
|
TextWrapping="Wrap"
|
|
Margin="0,0,0,5"/>
|
|
<ComboBox ItemsSource="{Binding AvailablePriorities}"
|
|
SelectedItem="{Binding SelectedProcessPriority}"
|
|
Padding="5" Margin="0,0,0,10"
|
|
ToolTip="Optional: Select the process priority to apply when this process starts"/>
|
|
|
|
<TextBlock Text="Association Priority:" Margin="0,0,0,5"/>
|
|
<TextBox Text="{Binding Priority}"
|
|
Padding="5" Margin="0,0,0,10"
|
|
ToolTip="Higher priority associations take precedence when multiple match"/>
|
|
|
|
<TextBlock Text="Description:" Margin="0,0,0,5"/>
|
|
<TextBox Text="{Binding Description}"
|
|
Padding="5" Margin="0,0,0,15"/>
|
|
|
|
<Button Content="Add Rule"
|
|
Command="{Binding AddAssociationCommand}"
|
|
Padding="10,8"/>
|
|
|
|
<Button Content="Update Selected Rule"
|
|
Command="{Binding UpdateAssociationCommand}"
|
|
Padding="10,8"
|
|
Margin="0,8,0,0"/>
|
|
|
|
<Separator Margin="0,15,0,15"/>
|
|
|
|
<TextBlock Text="Use Running Process:"
|
|
FontWeight="Bold" Margin="0,0,0,10"/>
|
|
|
|
<ComboBox ItemsSource="{Binding RunningProcesses}"
|
|
SelectedItem="{Binding SelectedProcess}"
|
|
DisplayMemberPath="Name"
|
|
Padding="5" Margin="0,0,0,10"
|
|
ToolTip="Select a currently running process to use its executable"/>
|
|
|
|
<Button Content="Use Selected Process"
|
|
Command="{Binding UseSelectedProcessForAssociationCommand}"
|
|
Padding="10,5"
|
|
ToolTip="Use the executable from the selected running process"/>
|
|
</StackPanel>
|
|
</ScrollViewer>
|
|
</GroupBox>
|
|
</Grid>
|
|
</TabItem>
|
|
|
|
<!-- Automation Monitoring Tab -->
|
|
<TabItem Header="Automation Monitoring">
|
|
<ScrollViewer Margin="10">
|
|
<StackPanel>
|
|
<!-- Service Control -->
|
|
<GroupBox Header="Automation Service" Margin="0,0,0,15">
|
|
<StackPanel>
|
|
<TextBlock Text="Automation monitoring watches process start/stop events and applies configured power plan, CPU mask, and priority rules."
|
|
Foreground="{DynamicResource TextSecondaryBrush}"
|
|
TextWrapping="Wrap"
|
|
Margin="0,0,0,10"/>
|
|
<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
|
|
<TextBlock Text="Status: " VerticalAlignment="Center"/>
|
|
<TextBlock Text="{Binding ServiceStatus}"
|
|
Foreground="{Binding IsServiceRunning, Converter={StaticResource BoolToColorConverter}}"
|
|
FontWeight="Bold" VerticalAlignment="Center"/>
|
|
</StackPanel>
|
|
|
|
<StackPanel Orientation="Horizontal">
|
|
<Button Content="Start Automation Monitoring"
|
|
Command="{Binding StartMonitoringCommand}"
|
|
IsEnabled="{Binding IsServiceRunning, Converter={StaticResource InverseBoolConverter}}"
|
|
Padding="15,8" Margin="0,0,10,0"/>
|
|
<Button Content="Stop Automation Monitoring"
|
|
Command="{Binding StopMonitoringCommand}"
|
|
IsEnabled="{Binding IsServiceRunning}"
|
|
Padding="15,8"/>
|
|
</StackPanel>
|
|
</StackPanel>
|
|
</GroupBox>
|
|
|
|
<!-- Default Power Plan -->
|
|
<GroupBox Header="Default Power Plan (fallback when no rule matches)" Margin="0,0,0,15">
|
|
<StackPanel>
|
|
<TextBlock Text="Power plan to use when no associated processes are running:"
|
|
Foreground="{DynamicResource TextSecondaryBrush}" Margin="0,0,0,10"/>
|
|
|
|
<ComboBox ItemsSource="{Binding AvailablePowerPlans}"
|
|
SelectedItem="{Binding DefaultPowerPlan}"
|
|
DisplayMemberPath="Name"
|
|
Padding="5" Margin="0,0,0,10"/>
|
|
|
|
<Button Content="Set Default Power Plan"
|
|
Command="{Binding SetDefaultPowerPlanCommand}"
|
|
Padding="10,5" HorizontalAlignment="Left"/>
|
|
</StackPanel>
|
|
</GroupBox>
|
|
|
|
<!-- Automation Monitoring Settings -->
|
|
<GroupBox Header="Automation Monitoring Settings" Margin="0,0,0,15">
|
|
<StackPanel>
|
|
<CheckBox Content="Enable Event-Based Automation (WMI)"
|
|
IsChecked="{Binding IsEventBasedMonitoringEnabled}"
|
|
Margin="0,0,0,10"/>
|
|
|
|
<CheckBox Content="Enable Automation Fallback Polling"
|
|
IsChecked="{Binding IsFallbackPollingEnabled}"
|
|
Margin="0,0,0,10"/>
|
|
|
|
<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
|
|
<TextBlock Text="Polling Interval (seconds): "
|
|
VerticalAlignment="Center" Margin="0,0,10,0"/>
|
|
<TextBox Text="{Binding PollingIntervalSeconds}"
|
|
Width="60" Padding="5"/>
|
|
</StackPanel>
|
|
|
|
<CheckBox Content="Prevent Duplicate Power Plan Changes"
|
|
IsChecked="{Binding PreventDuplicatePowerPlanChanges}"
|
|
Margin="0,0,0,10"/>
|
|
|
|
<StackPanel Orientation="Horizontal" Margin="0,0,0,15">
|
|
<TextBlock Text="Power Plan Change Delay (ms): "
|
|
VerticalAlignment="Center" Margin="0,0,10,0"/>
|
|
<TextBox Text="{Binding PowerPlanChangeDelayMs}"
|
|
Width="80" Padding="5"/>
|
|
</StackPanel>
|
|
|
|
<Button Content="Save Configuration"
|
|
Command="{Binding SaveConfigurationCommand}"
|
|
Padding="15,8" HorizontalAlignment="Left"/>
|
|
</StackPanel>
|
|
</GroupBox>
|
|
</StackPanel>
|
|
</ScrollViewer>
|
|
</TabItem>
|
|
</TabControl>
|
|
|
|
<Border Grid.Row="1"
|
|
VerticalAlignment="Bottom"
|
|
Margin="10"
|
|
Padding="10,7"
|
|
CornerRadius="6"
|
|
BorderThickness="1"
|
|
Opacity="{Binding StatusOpacity}"
|
|
Visibility="{Binding StatusMessage, Converter={x:Static converters:StringToVisibilityConverter.Instance}}">
|
|
<Border.Style>
|
|
<Style TargetType="Border">
|
|
<Setter Property="Background" Value="{DynamicResource SuccessBackgroundBrush}"/>
|
|
<Setter Property="BorderBrush" Value="{DynamicResource SuccessBorderBrush}"/>
|
|
<Style.Triggers>
|
|
<DataTrigger Binding="{Binding HasError}" Value="True">
|
|
<Setter Property="Background" Value="{DynamicResource ErrorBackgroundBrush}"/>
|
|
<Setter Property="BorderBrush" Value="{DynamicResource ErrorBorderBrush}"/>
|
|
</DataTrigger>
|
|
</Style.Triggers>
|
|
</Style>
|
|
</Border.Style>
|
|
<TextBlock Text="{Binding StatusMessage}">
|
|
<TextBlock.Style>
|
|
<Style TargetType="TextBlock">
|
|
<Setter Property="Foreground" Value="{DynamicResource SuccessTextBrush}"/>
|
|
<Style.Triggers>
|
|
<DataTrigger Binding="{Binding HasError}" Value="True">
|
|
<Setter Property="Foreground" Value="{DynamicResource ErrorTextBrush}"/>
|
|
</DataTrigger>
|
|
</Style.Triggers>
|
|
</Style>
|
|
</TextBlock.Style>
|
|
</TextBlock>
|
|
</Border>
|
|
</Grid>
|
|
</UserControl>
|