Files
ThreadPilot/Views/SettingsView.xaml
T
Prime Build 024673dcbe Add safe in-app updater (#28)
## Summary

Adds a safe in-app updater for ThreadPilot. This PR does not bump the app version and does not prepare a release; version and release metadata will be handled separately for v1.4.0.

## Type of Change

- [x] Feature
- [x] Security hardening
- [x] Documentation
- [x] Added/updated tests

## Update flow

- Checks for updates on demand from Settings.
- Performs background startup checks only when enabled and the last check is older than the configured interval.
- Defaults to a 7-day interval.
- Excludes prereleases by default.
- Notifies users when an update is available.
- Requires explicit user action before download/install.

## Security and safety

- Uses release metadata from the official `PrimeBuild-pc/ThreadPilot` repository only.
- Selects safe ThreadPilot installer assets from GitHub HTTPS release assets.
- Downloads into a ThreadPilot-owned temp update directory.
- Verifies SHA256 checksums when `SHA256SUMS.txt` is available.
- Rejects checksum mismatches.
- Performs best-effort Authenticode verification and rejects explicitly invalid signatures.
- Starts the installer elevated without shell command construction.
- Prevents concurrent install attempts.

## User data preservation

- Update flow does not delete AppData, settings, profiles, CPU masks, rules, custom/imported power plans, or logs.
- Only updater temp files are cleaned.
- Full uninstall behavior remains separate.

## Validation

- `dotnet restore ThreadPilot_1.sln`: passed
- `dotnet build ThreadPilot_1.sln`: passed, 0 warnings, 0 errors
- `dotnet test ThreadPilot_1.sln`: passed, 537 tests

## Release note

This PR intentionally leaves `ThreadPilot.csproj` at `1.3.1`. The `1.4.0` version bump, changelog, packaging metadata, and tag should happen in a separate release-prep branch after this PR is merged.
2026-06-07 06:06:53 +02:00

476 lines
29 KiB
XML

<UserControl x:Class="ThreadPilot.Views.SettingsView"
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:local="clr-namespace:ThreadPilot.Views"
xmlns:models="clr-namespace:ThreadPilot.Models"
xmlns:converters="clr-namespace:ThreadPilot.Converters"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="800">
<UserControl.Resources>
<Style x:Key="SectionHeaderStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="{DynamicResource SectionTitleFontSize}"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Margin" Value="0,0,0,8"/>
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style x:Key="DescriptionStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="{DynamicResource CaptionFontSize}"/>
<Setter Property="Foreground" Value="{DynamicResource TextSecondaryBrush}"/>
<Setter Property="Margin" Value="0,2,0,0"/>
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
<Style x:Key="SettingsCardStyle" TargetType="Border" BasedOn="{StaticResource StandardCardStyle}">
<Setter Property="Background" Value="{DynamicResource CardSurfaceBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderSubtleBrush}"/>
<Setter Property="Padding" Value="{DynamicResource StandardCardPadding}"/>
</Style>
</UserControl.Resources>
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="0,0,0,16">
<TextBlock Text="{DynamicResource SettingsView_Title}" Style="{StaticResource PageTitleTextStyle}" Margin="0,0,0,4"/>
<TextBlock Text="{DynamicResource SettingsView_Subtitle}"
Style="{StaticResource PageSubtitleTextStyle}"/>
</StackPanel>
<!-- Settings Content -->
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
<WrapPanel HorizontalAlignment="Left">
<!-- Notifications Section -->
<StackPanel Width="372" Margin="0,0,16,16">
<TextBlock Text="{DynamicResource SettingsView_Notifications}" Style="{StaticResource SectionHeaderStyle}" Margin="0,0,0,8"/>
<Border Style="{StaticResource SettingsCardStyle}">
<StackPanel>
<CheckBox Content="{DynamicResource SettingsView_EnableNotifications}"
IsChecked="{Binding Settings.EnableNotifications}"
Margin="0,0,0,10"/>
<StackPanel Margin="20,0,0,10"
IsEnabled="{Binding Settings.EnableNotifications}">
<TextBlock Text="{DynamicResource SettingsView_NotificationLevel}" FontWeight="SemiBold" Margin="0,0,0,4"/>
<ComboBox SelectedValue="{Binding Settings.NotificationLevel}"
SelectedValuePath="Tag">
<ComboBoxItem Content="{DynamicResource SettingsView_NotificationLevelAll}" Tag="{x:Static models:NotificationLevelProfile.All}"/>
<ComboBoxItem Content="{DynamicResource SettingsView_NotificationLevelWarningsErrors}" Tag="{x:Static models:NotificationLevelProfile.WarningsAndErrorsOnly}"/>
<ComboBoxItem Content="{DynamicResource SettingsView_NotificationLevelSilent}" Tag="{x:Static models:NotificationLevelProfile.Silent}"/>
</ComboBox>
</StackPanel>
<CheckBox Content="{DynamicResource SettingsView_EnableBalloon}"
IsChecked="{Binding Settings.EnableBalloonNotifications}"
IsEnabled="{Binding Settings.EnableNotifications}"
Margin="20,0,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_EnableToast}"
IsChecked="{Binding Settings.EnableToastNotifications}"
IsEnabled="{Binding Settings.EnableNotifications}"
Margin="20,0,0,10"/>
<Separator Margin="0,10"/>
<TextBlock Text="{DynamicResource SettingsView_NotificationTypes}" FontWeight="SemiBold" Margin="0,5"/>
<CheckBox Content="{DynamicResource SettingsView_NotifyPowerPlan}"
IsChecked="{Binding Settings.EnablePowerPlanChangeNotifications}"
IsEnabled="{Binding Settings.EnableNotifications}"
Margin="20,5,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_NotifyProcess}"
IsChecked="{Binding Settings.EnableProcessMonitoringNotifications}"
IsEnabled="{Binding Settings.EnableNotifications}"
Margin="20,0,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_NotifyError}"
IsChecked="{Binding Settings.EnableErrorNotifications}"
IsEnabled="{Binding Settings.EnableNotifications}"
Margin="20,0,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_NotifySuccess}"
IsChecked="{Binding Settings.EnableSuccessNotifications}"
IsEnabled="{Binding Settings.EnableNotifications}"
Margin="20,0,0,10"/>
<Separator Margin="0,10"/>
<Grid Margin="0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{DynamicResource SettingsView_Duration}" VerticalAlignment="Center"/>
<Slider Grid.Column="1"
Value="{Binding Settings.NotificationDisplayDurationMs}"
Minimum="1000" Maximum="30000"
TickFrequency="1000"
IsSnapToTickEnabled="True"
Margin="10,0"/>
<TextBlock Grid.Column="2"
Text="{Binding Settings.NotificationDisplayDurationMs}"
VerticalAlignment="Center" MinWidth="40"/>
</Grid>
<Button Content="{DynamicResource SettingsView_TestNotification}"
Command="{Binding TestNotificationCommand}"
HorizontalAlignment="Left"
Margin="0,10,0,0"
Padding="15,5"/>
</StackPanel>
</Border>
</StackPanel>
<!-- System Tray Section -->
<StackPanel Width="372" Margin="0,0,16,16">
<TextBlock Text="{DynamicResource SettingsView_SystemTray}" Style="{StaticResource SectionHeaderStyle}" Margin="0,0,0,8"/>
<Border Style="{StaticResource SettingsCardStyle}">
<StackPanel>
<CheckBox Content="{DynamicResource SettingsView_ShowTrayIcon}"
IsChecked="{Binding Settings.ShowTrayIcon}"
Margin="0,0,0,10"/>
<CheckBox Content="{DynamicResource SettingsView_MinimizeToTray}"
IsChecked="{Binding Settings.MinimizeToTray}"
IsEnabled="{Binding Settings.ShowTrayIcon}"
Margin="20,0,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_CloseToTray}"
IsChecked="{Binding Settings.CloseToTray}"
IsEnabled="{Binding Settings.ShowTrayIcon}"
Margin="20,0,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_StartMinimized}"
IsChecked="{Binding Settings.StartMinimized}"
Margin="20,0,0,10"/>
<Separator Margin="0,10"/>
<CheckBox Content="{DynamicResource SettingsView_QuickApply}"
IsChecked="{Binding Settings.EnableQuickApplyFromTray}"
IsEnabled="{Binding Settings.ShowTrayIcon}"
Margin="0,5"/>
<CheckBox Content="{DynamicResource SettingsView_MonitoringControl}"
IsChecked="{Binding Settings.EnableMonitoringControlFromTray}"
IsEnabled="{Binding Settings.ShowTrayIcon}"
Margin="0,0,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_DetailedTooltips}"
IsChecked="{Binding Settings.ShowDetailedTooltips}"
IsEnabled="{Binding Settings.ShowTrayIcon}"
Margin="0,0,0,10"/>
</StackPanel>
</Border>
</StackPanel>
<!-- Basic Preferences Section -->
<StackPanel Width="372" Margin="0,0,16,16">
<TextBlock Text="{DynamicResource SettingsView_BasicPreferences}" Style="{StaticResource SectionHeaderStyle}" Margin="0,0,0,8"/>
<Border Style="{StaticResource SettingsCardStyle}">
<StackPanel>
<TextBlock Text="{DynamicResource SettingsView_Autostart}" FontWeight="SemiBold" Margin="0,0,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_StartWithWindows}"
IsChecked="{Binding Settings.AutostartWithWindows}"
Margin="0,0,0,5"/>
<TextBlock Text="{DynamicResource SettingsView_AutostartDescription}"
Style="{StaticResource DescriptionStyle}"
Margin="20,0,0,15"/>
<CheckBox Content="{DynamicResource SettingsView_LowImpactMode}"
IsChecked="{Binding Settings.EnableSelfLowImpactMode}"
Margin="0,0,0,5"/>
<TextBlock Text="{DynamicResource SettingsView_LowImpactDescription}"
Style="{StaticResource DescriptionStyle}"
Margin="20,0,0,15"/>
<Separator Margin="0,0,0,15"/>
<TextBlock Text="{DynamicResource SettingsView_Appearance}" FontWeight="SemiBold" Margin="0,0,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_UseDarkTheme}"
IsChecked="{Binding Settings.UseDarkTheme}"
Margin="0,0,0,5"/>
<TextBlock Text="{DynamicResource SettingsView_ThemeDescription}"
Style="{StaticResource DescriptionStyle}"
Margin="20,0,0,5"/>
<Separator Margin="0,10"/>
<TextBlock Text="{DynamicResource SettingsView_Language}" FontWeight="SemiBold" Margin="0,5,0,5"/>
<ComboBox SelectedValue="{Binding Settings.Language}" SelectedValuePath="Tag" Margin="0,0,0,5">
<ComboBoxItem Content="{DynamicResource SettingsView_LanguageEnUs}" Tag="en-US"/>
<ComboBoxItem Content="{DynamicResource SettingsView_LanguageZhCn}" Tag="zh-CN"/>
</ComboBox>
<TextBlock Text="{DynamicResource SettingsView_LanguageDescription}"
Style="{StaticResource DescriptionStyle}"
Margin="0,2,0,5"/>
</StackPanel>
</Border>
</StackPanel>
<!-- Rules & automation Section -->
<StackPanel Width="372" Margin="0,0,16,16">
<TextBlock Text="{DynamicResource SettingsView_RulesAutomation}" Style="{StaticResource SectionHeaderStyle}" Margin="0,0,0,8"/>
<Border Style="{StaticResource SettingsCardStyle}">
<StackPanel>
<TextBlock Text="{DynamicResource SettingsView_RuleAutoApply}" FontWeight="SemiBold" Margin="0,0,0,5"/>
<CheckBox IsChecked="{Binding Settings.ApplyPersistentRulesOnProcessStart}"
Margin="0,0,0,5">
<TextBlock Text="{DynamicResource SettingsView_ApplyOnStart}"
TextWrapping="Wrap"/>
</CheckBox>
<TextBlock Text="{DynamicResource SettingsView_ApplyOnStartDescription}"
Style="{StaticResource DescriptionStyle}"
Margin="20,0,0,15"/>
<Separator Margin="0,0,0,15"/>
<CheckBox Content="{DynamicResource SettingsView_EnableWmi}"
IsChecked="{Binding Settings.EnableWmiMonitoring}"
Margin="0,0,0,5"/>
<TextBlock Text="{DynamicResource SettingsView_WmiDescription}"
Style="{StaticResource DescriptionStyle}"
Margin="20,0,0,15"/>
<CheckBox Content="{DynamicResource SettingsView_EnableFallback}"
IsChecked="{Binding Settings.EnableFallbackPolling}"
Margin="0,0,0,5"/>
<TextBlock Text="{DynamicResource SettingsView_FallbackDescription}"
Style="{StaticResource DescriptionStyle}"
Margin="20,0,0,15"/>
<Separator Margin="0,0,0,15"/>
<Grid Margin="0,0,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{DynamicResource SettingsView_PollingInterval}" VerticalAlignment="Center"/>
<Slider Grid.Column="1"
Value="{Binding Settings.PollingIntervalMs}"
Minimum="1000" Maximum="30000"
TickFrequency="1000"
IsSnapToTickEnabled="True"
Margin="10,0"/>
<TextBlock Grid.Column="2"
Text="{Binding Settings.PollingIntervalMs}"
VerticalAlignment="Center" MinWidth="40"/>
</Grid>
<Grid Margin="0,5,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{DynamicResource SettingsView_FallbackPollingInterval}" VerticalAlignment="Center"/>
<Slider Grid.Column="1"
Value="{Binding Settings.FallbackPollingIntervalMs}"
Minimum="5000" Maximum="60000"
TickFrequency="5000"
IsSnapToTickEnabled="True"
Margin="10,0"/>
<TextBlock Grid.Column="2"
Text="{Binding Settings.FallbackPollingIntervalMs}"
VerticalAlignment="Center" MinWidth="40"/>
</Grid>
</StackPanel>
</Border>
</StackPanel>
<!-- Advanced Section -->
<StackPanel Width="372" Margin="0,0,16,16">
<TextBlock Text="{DynamicResource SettingsView_Advanced}" Style="{StaticResource SectionHeaderStyle}" Margin="0,0,0,8"/>
<Border Style="{StaticResource SettingsCardStyle}">
<StackPanel>
<CheckBox Content="{DynamicResource SettingsView_NotificationHistory}"
IsChecked="{Binding Settings.EnableNotificationHistory}"
Margin="0,0,0,10"/>
<Grid Margin="0,5" IsEnabled="{Binding Settings.EnableNotificationHistory}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{DynamicResource SettingsView_MaxHistory}" VerticalAlignment="Center"/>
<Slider Grid.Column="1"
Value="{Binding Settings.MaxNotificationHistoryItems}"
Minimum="10" Maximum="1000"
TickFrequency="10"
IsSnapToTickEnabled="True"
Margin="10,0"/>
<TextBlock Grid.Column="2"
Text="{Binding Settings.MaxNotificationHistoryItems}"
VerticalAlignment="Center" MinWidth="40"/>
</Grid>
<CheckBox Content="{DynamicResource SettingsView_AutoHide}"
IsChecked="{Binding Settings.AutoHideNotifications}"
Margin="0,10,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_NotificationSound}"
IsChecked="{Binding Settings.EnableNotificationSound}"
Margin="0,0,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_DebugLogging}"
IsChecked="{Binding Settings.EnableDebugLogging}"
Margin="0,0,0,5"/>
<CheckBox Content="{DynamicResource SettingsView_PerformanceCounters}"
IsChecked="{Binding Settings.EnablePerformanceCounters}"
Margin="0,0,0,10"/>
</StackPanel>
</Border>
</StackPanel>
<!-- About Section -->
<StackPanel Width="372" Margin="0,0,16,16">
<TextBlock Text="{DynamicResource SettingsView_About}" Style="{StaticResource SectionHeaderStyle}" Margin="0,0,0,8"/>
<Border Style="{StaticResource SettingsCardStyle}">
<StackPanel>
<TextBlock Text="{DynamicResource SettingsView_ThreadPilot}" FontWeight="SemiBold" FontSize="14"/>
<TextBlock Text="{DynamicResource SettingsView_Version}" FontWeight="SemiBold" Margin="0,8,0,0"/>
<TextBlock Text="{Binding ApplicationVersion}" Margin="0,0,0,10"/>
<CheckBox Content="{DynamicResource SettingsView_EnableAutomaticUpdateChecks}"
IsChecked="{Binding Settings.EnableAutomaticUpdateChecks}"
Margin="0,0,0,6"/>
<Grid Margin="20,0,0,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{DynamicResource SettingsView_UpdateIntervalDays}" VerticalAlignment="Center"/>
<Slider Grid.Column="1"
Value="{Binding Settings.UpdateCheckIntervalDays}"
Minimum="1" Maximum="30"
TickFrequency="1"
IsSnapToTickEnabled="True"
Margin="10,0"/>
<TextBlock Grid.Column="2"
Text="{Binding Settings.UpdateCheckIntervalDays}"
VerticalAlignment="Center" MinWidth="30"/>
</Grid>
<CheckBox Content="{DynamicResource SettingsView_IncludePrereleaseUpdates}"
IsChecked="{Binding Settings.IncludePrereleaseUpdates}"
Margin="0,0,0,10"/>
<TextBlock Text="{DynamicResource SettingsView_LatestVersion}" FontWeight="SemiBold" Margin="0,0,0,0"/>
<TextBlock Text="{Binding LatestUpdateVersion}" Margin="0,0,0,6"/>
<TextBlock Text="{DynamicResource SettingsView_LastUpdateCheck}" FontWeight="SemiBold" Margin="0,0,0,0"/>
<TextBlock Text="{Binding LastUpdateCheckText}" Margin="0,0,0,10"/>
<TextBlock Text="{DynamicResource SettingsView_Copyright}" Margin="0,0,0,4"/>
<TextBlock Text="{DynamicResource SettingsView_License}" Style="{StaticResource DescriptionStyle}"/>
<Separator Margin="0,12,0,12"/>
<Button Content="{DynamicResource SettingsView_CheckUpdates}"
Command="{Binding CheckUpdatesCommand}"
Padding="15,6"
HorizontalAlignment="Left"/>
<Button Content="{DynamicResource SettingsView_DownloadInstallUpdate}"
Command="{Binding DownloadAndInstallUpdateCommand}"
IsEnabled="{Binding CanDownloadAndInstallUpdate}"
Padding="15,6"
HorizontalAlignment="Left"
Margin="0,8,0,0"/>
<TextBlock Text="{DynamicResource SettingsView_UpdatesDescription}"
Style="{StaticResource DescriptionStyle}"
Margin="0,6,0,0"/>
</StackPanel>
</Border>
</StackPanel>
</WrapPanel>
</ScrollViewer>
<!-- Footer with buttons and status -->
<Grid Grid.Row="2" Margin="0,20,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- Status -->
<Border Grid.Row="0"
Margin="0,0,0,10"
Padding="10,7"
CornerRadius="{DynamicResource StandardCardCornerRadius}"
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>
<!-- Buttons -->
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="{DynamicResource SettingsView_ResetDefaults}"
Command="{Binding ResetToDefaultsCommand}"
Margin="0,0,10,0"
Padding="15,8"/>
<Button Content="{DynamicResource SettingsView_ExportConfig}"
Command="{Binding ExportSettingsCommand}"
Margin="0,0,10,0"
Padding="15,8"/>
<Button Content="{DynamicResource SettingsView_ImportConfig}"
Command="{Binding ImportSettingsCommand}"
Margin="0,0,20,0"
Padding="15,8"/>
<Button Content="{DynamicResource SettingsView_SaveSettings}"
Command="{Binding SaveSettingsCommand}"
IsEnabled="{Binding CanSaveSettings}"
Padding="20,8"/>
</StackPanel>
</Grid>
</Grid>
</UserControl>