UI improvements & cancel execution when closing during execution (#455)

This commit is contained in:
Jeffrey
2026-02-06 23:44:39 +01:00
committed by GitHub
parent 6e65a07184
commit 3af62159a5
2 changed files with 130 additions and 42 deletions

View File

@@ -159,6 +159,13 @@
<Trigger Property="SelectedIndex" Value="-1">
<Setter TargetName="ClosedAccentLine" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="ClosedAccentLine" Property="Visibility" Value="Collapsed"/>
<Setter Property="Background" Value="{DynamicResource ButtonDisabled}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderColor}"/>
<Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}"/>
<Setter Property="Opacity" Value="0.6"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
@@ -238,7 +245,7 @@
<!-- Category header text style -->
<Style x:Key="CategoryHeaderTextBlock" TargetType="TextBlock">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="15"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="Margin" Value="0,0,0,10"/>
<Setter Property="Foreground" Value="{DynamicResource FgColor}"/>
</Style>
@@ -246,13 +253,15 @@
<!-- Overview changes text style -->
<Style x:Key="OverviewNoChangesTextStyle" TargetType="TextBlock">
<Setter Property="Foreground" Value="{DynamicResource FgColor}"/>
<Setter Property="Margin" Value="0,0,0,8"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="Margin" Value="0,8,0,0"/>
</Style>
<Style x:Key="OverviewChangeBulletStyle" TargetType="TextBlock">
<Setter Property="Foreground" Value="{DynamicResource FgColor}"/>
<Setter Property="Margin" Value="0,8,0,0"/>
<Setter Property="Margin" Value="0,0,0,8"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
@@ -261,6 +270,41 @@
<Setter Property="CaretBrush" Value="{DynamicResource FgColor}"/>
</Style>
<!-- User TextBox Style with disabled state -->
<Style x:Key="UserTextBoxStyle" TargetType="TextBox">
<Setter Property="CaretBrush" Value="{DynamicResource FgColor}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{DynamicResource FgColor}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="Margin" Value="1,0,0,1"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Padding" Value="0"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource ButtonDisabled}"/>
<Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}"/>
<Setter Property="Opacity" Value="0.6"/>
</Trigger>
</Style.Triggers>
</Style>
<!-- User TextBox Border Style with disabled state -->
<Style x:Key="UserTextBoxBorderStyle" TargetType="Border">
<Setter Property="BorderBrush" Value="{DynamicResource ButtonBorderColor}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="CornerRadius" Value="4"/>
<Setter Property="Background" Value="{DynamicResource ComboBgColor}"/>
<Setter Property="Padding" Value="8,6"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource ButtonDisabled}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderColor}"/>
<Setter Property="Opacity" Value="0.6"/>
</Trigger>
</Style.Triggers>
</Style>
<!-- CheckBox Style -->
<Style TargetType="CheckBox">
<Setter Property="Foreground" Value="{DynamicResource FgColor}"/>
@@ -291,6 +335,13 @@
<Setter TargetName="CheckBoxBorder" Property="BorderBrush" Value="{DynamicResource ButtonBg}"/>
<Setter TargetName="CheckMark" Property="Foreground" Value="White"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="CheckBoxBorder" Property="Background" Value="{DynamicResource ButtonDisabled}"/>
<Setter TargetName="CheckBoxBorder" Property="BorderBrush" Value="{DynamicResource BorderColor}"/>
<Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}"/>
<Setter Property="Opacity" Value="0.6"/>
<Setter TargetName="CheckMark" Property="Foreground" Value="{DynamicResource ButtonTextDisabled}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
@@ -744,18 +795,27 @@
<Grid>
<ScrollViewer VerticalScrollBarVisibility="Auto" Margin="0,-20,0,0" Padding="20,10,20,0">
<StackPanel Margin="0,10,0,5">
<!-- Selected Changes -->
<Border BorderBrush="{DynamicResource BorderColor}" BorderThickness="1" CornerRadius="4" Background="{DynamicResource CardBgColor}" Padding="16,12,16,4" Margin="0,0,0,16">
<StackPanel>
<TextBlock Text="Selected Changes" Style="{StaticResource CategoryHeaderTextBlock}"/>
<StackPanel x:Name="OverviewChangesPanel"/>
<StackPanel Margin="0,0,0,3"/>
</StackPanel>
</Border>
<!-- Apply Changes To -->
<Border BorderBrush="{DynamicResource BorderColor}" BorderThickness="1" CornerRadius="4" Background="{DynamicResource CardBgColor}" Padding="16,12" Margin="0,0,0,16">
<StackPanel>
<TextBlock Text="Apply Changes To" FontWeight="Bold" FontSize="14" Foreground="{DynamicResource FgColor}" Margin="0,0,0,8"/>
<ComboBox x:Name="UserSelectionCombo" Margin="0,0,0,12" AutomationProperties.Name="Apply Changes To">
<TextBlock Text="Apply Changes To" Style="{StaticResource CategoryHeaderTextBlock}"/>
<ComboBox x:Name="UserSelectionCombo" Margin="0,0,0,6" AutomationProperties.Name="Apply Changes To">
<ComboBoxItem Content="Current User" IsSelected="True"/>
<ComboBoxItem Content="Other User"/>
<ComboBoxItem Content="Windows Default User (Sysprep)"/>
</ComboBox>
<StackPanel x:Name="OtherUserPanel" Visibility="Collapsed" Margin="0,0,0,12">
<StackPanel x:Name="OtherUserPanel" Visibility="Collapsed" Margin="0,0,0,6">
<TextBlock x:Name="UsernameValidationMessage" Text="" FontStyle="Italic" Foreground="{DynamicResource CloseHover}" FontSize="11" Margin="3,0,0,4" TextWrapping="Wrap"/>
<Border BorderBrush="{DynamicResource ButtonBorderColor}" BorderThickness="1" CornerRadius="4" Background="{DynamicResource ComboBgColor}" Padding="8,6">
<Border Style="{StaticResource UserTextBoxBorderStyle}" IsEnabled="{Binding ElementName=OtherUsernameTextBox, Path=IsEnabled}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
@@ -763,28 +823,28 @@
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="&#xE77B;" FontFamily="Segoe MDL2 Assets" FontSize="14" VerticalAlignment="Center" Margin="4,0,8,0" Foreground="{DynamicResource FgColor}"/>
<TextBlock x:Name="UsernameTextBoxPlaceholder" Grid.Column="1" Text="Enter username" Foreground="{DynamicResource FgColor}" Opacity="0.5" FontSize="13" Margin="3,0,0,1" VerticalAlignment="Center" IsHitTestVisible="False"/>
<TextBox x:Name="OtherUsernameTextBox" Grid.Column="1" Background="Transparent" Foreground="{DynamicResource FgColor}" BorderThickness="0" FontSize="13" Margin="1,0,0,1" VerticalAlignment="Center" Text="" Padding="0" AutomationProperties.Name="Enter username"/>
<TextBox x:Name="OtherUsernameTextBox" Grid.Column="1" Style="{StaticResource UserTextBoxStyle}" Text="" AutomationProperties.Name="Enter username"/>
</Grid>
</Border>
</StackPanel>
<TextBlock x:Name="UserSelectionDescription" Text="Changes will be applied to the currently logged-in user profile." Foreground="{DynamicResource FgColor}" FontSize="12" TextWrapping="Wrap"/>
<TextBlock x:Name="UserSelectionDescription" Text="Changes will be applied to the currently logged-in user profile." Foreground="{DynamicResource FgColor}" FontSize="12" TextWrapping="Wrap" Margin="0,6,0,3"/>
</StackPanel>
</Border>
<!-- Selected Changes -->
<Border BorderBrush="{DynamicResource BorderColor}" BorderThickness="1" CornerRadius="4" Background="{DynamicResource CardBgColor}" Padding="16,12" Margin="0,0,0,16">
<!-- Options -->
<Border BorderBrush="{DynamicResource BorderColor}" BorderThickness="1" CornerRadius="4" Background="{DynamicResource CardBgColor}" Padding="16,12,16,3" Margin="0,0,0,16">
<StackPanel>
<TextBlock Text="Selected Changes" FontWeight="Bold" FontSize="14" Foreground="{DynamicResource FgColor}"/>
<StackPanel x:Name="OverviewChangesPanel"/>
</StackPanel>
</Border>
<TextBlock Text="Options" Style="{StaticResource CategoryHeaderTextBlock}"/>
<!-- System Restore Point -->
<Border BorderBrush="{DynamicResource BorderColor}" BorderThickness="1" CornerRadius="4" Background="{DynamicResource CardBgColor}" Padding="16,12" Margin="0,0,0,16">
<StackPanel>
<TextBlock Text="System Restore Point" FontWeight="Bold" FontSize="14" Foreground="{DynamicResource FgColor}" Margin="0,0,0,8"/>
<TextBlock Text="A restore point will allow you to revert your system to a previous state using the built-in System Restore feature. (Recommended)" Foreground="{DynamicResource FgColor}" FontSize="12" Margin="0,0,0,10" TextWrapping="Wrap"/>
<CheckBox x:Name="RestorePointCheckBox" Content="Create system restore point" Foreground="{DynamicResource FgColor}" AutomationProperties.Name="Create system restore point"/>
<!-- Restore Point Option -->
<StackPanel>
<CheckBox x:Name="RestorePointCheckBox" Style="{StaticResource FeatureCheckboxStyle}" Content="Create a system restore point (Recommended)" AutomationProperties.Name="Create a system restore point (Recommended)"/>
</StackPanel>
<!-- Restart Explorer Option -->
<StackPanel>
<CheckBox x:Name="RestartExplorerCheckBox" Style="{StaticResource FeatureCheckboxStyle}" Content="Restart the Windows Explorer process to apply all changes immediately" AutomationProperties.Name="Restart the Windows Explorer process to apply all changes immediately"/>
</StackPanel>
</StackPanel>
</Border>

View File

@@ -105,6 +105,7 @@ $script:ControlParams = 'WhatIf', 'Confirm', 'Verbose', 'Debug', 'LogPath', 'Sil
$script:GuiConsoleOutput = $null
$script:GuiConsoleScrollViewer = $null
$script:GuiWindow = $null
$script:CancelRequested = $false
# Check if current powershell environment is limited by security policies
if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
@@ -598,10 +599,9 @@ function OpenGUI {
$window.Close()
})
# Ensure closing the window via any means properly exits the script
# Ensure closing the main window stops all execution
$window.Add_Closing({
Stop-Transcript
Exit
$script:CancelRequested = $true
})
# Implement window resize functionality
@@ -1710,25 +1710,18 @@ function OpenGUI {
try {
ExecuteAllChanges
if (-not $script:Params.ContainsKey("Sysprep") -and -not $script:Params.ContainsKey("User") -and -not $script:Params.ContainsKey("NoRestartExplorer")) {
# Ask user if they want to restart Explorer now
$result = [System.Windows.MessageBox]::Show(
'Would you like to restart the Windows Explorer process now to apply all changes? Some changes may not take effect until a restart is performed.',
'Restart Windows Explorer?',
[System.Windows.MessageBoxButton]::YesNo,
[System.Windows.MessageBoxImage]::Question
)
if ($result -eq [System.Windows.MessageBoxResult]::Yes) {
RestartExplorer
}
else {
Write-ToConsole "Explorer process restart was skipped, please manually reboot your PC to apply all changes"
}
# Check if user wants to restart explorer (from checkbox)
$restartExplorerCheckBox = $window.FindName('RestartExplorerCheckBox')
if ($restartExplorerCheckBox -and $restartExplorerCheckBox.IsChecked -and -not $script:CancelRequested) {
RestartExplorer
}
Write-ToConsole ""
Write-ToConsole "All changes have been applied. Please check the output above for any errors."
if ($script:CancelRequested) {
Write-ToConsole "Script execution was cancelled by the user. Some changes may not have been applied."
} else {
Write-ToConsole "All changes have been applied. Please check the output above for any errors."
}
$finishBtn.Dispatcher.Invoke([action]{
$finishBtn.IsEnabled = $true
@@ -1751,6 +1744,33 @@ function OpenGUI {
LoadAppsIntoMainUI
# Update Current User label with username
if ($userSelectionCombo -and $userSelectionCombo.Items.Count -gt 0) {
$currentUserItem = $userSelectionCombo.Items[0]
if ($currentUserItem -is [System.Windows.Controls.ComboBoxItem]) {
$currentUserItem.Content = "Current User ($(GetUserName))"
}
}
# Disable Restart Explorer option if NoRestartExplorer parameter is set
$restartExplorerCheckBox = $window.FindName('RestartExplorerCheckBox')
if ($restartExplorerCheckBox -and $script:Params.ContainsKey("NoRestartExplorer")) {
$restartExplorerCheckBox.IsChecked = $false
$restartExplorerCheckBox.IsEnabled = $false
}
# Force Apply Changes To setting if Sysprep or User parameters are set
if ($script:Params.ContainsKey("Sysprep")) {
$userSelectionCombo.SelectedIndex = 2
$userSelectionCombo.IsEnabled = $false
}
elseif ($script:Params.ContainsKey("User")) {
$userSelectionCombo.SelectedIndex = 1
$userSelectionCombo.IsEnabled = $false
$otherUsernameTextBox.Text = $script:Params.Item("User")
$otherUsernameTextBox.IsEnabled = $false
}
UpdateNavigationButtons
})
@@ -2170,6 +2190,10 @@ function RemoveApps {
)
Foreach ($app in $appsList) {
if ($script:CancelRequested) {
return
}
Write-ToConsole "Attempting to remove $app..."
# Use WinGet only to remove OneDrive and Edge
@@ -2911,6 +2935,10 @@ function ExecuteAllChanges {
# Execute all parameters
foreach ($paramKey in $script:Params.Keys) {
if ($script:CancelRequested) {
return
}
if ($script:ControlParams -contains $paramKey) {
continue
}