Fix: Show reboot warning for undoing features that require it (#699)

This commit is contained in:
Jeffrey
2026-07-11 20:04:51 +02:00
committed by GitHub
parent 74dedc00e9
commit 3b78e8d4ed
5 changed files with 52 additions and 20 deletions
+10 -11
View File
@@ -1,10 +1,11 @@
# Restart the Windows Explorer process <#
function RestartExplorer { .SYNOPSIS
# Restarting Explorer while running in Sysprep or User context is not necessary Restarts Windows Explorer to apply system changes.
if ($script:Params.ContainsKey("Sysprep") -or $script:Params.ContainsKey("User")) {
return
}
.DESCRIPTION
Restarts the Explorer process to ensure all UI modifications take effect. Shows a warning if any of the applied features require a reboot to take full effect.
#>
function RestartExplorer {
if ($script:Params.ContainsKey("WhatIf")) { if ($script:Params.ContainsKey("WhatIf")) {
Write-Host "[WhatIf] Restart the Windows Explorer process" -ForegroundColor Cyan Write-Host "[WhatIf] Restart the Windows Explorer process" -ForegroundColor Cyan
return return
@@ -17,11 +18,9 @@ function RestartExplorer {
return return
} }
foreach ($paramKey in $script:Params.Keys) { $rebootFeatures = Get-RebootFeatureLabels
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) { foreach ($displayLabel in $rebootFeatures) {
$feature = $script:Features[$paramKey] Write-Host "Warning: '$displayLabel' requires a reboot to take full effect" -ForegroundColor Yellow
Write-Host "Warning: '$($feature.Label)' requires a reboot to take full effect" -ForegroundColor Yellow
}
} }
# Only restart if the powershell process matches the OS architecture. # Only restart if the powershell process matches the OS architecture.
+8 -1
View File
@@ -13,6 +13,13 @@ function Get-UndoFeatureLabel {
return [string]$script:FeatureLabelLookup[$FeatureId] return [string]$script:FeatureLabelLookup[$FeatureId]
} }
<#
.SYNOPSIS
Returns the tweak actions that are pending based on the current UI state.
.OUTPUTS
[PSCustomObject[]] Objects with Action, FeatureId, and Label properties.
#>
function Get-PendingTweakActions { function Get-PendingTweakActions {
param( param(
[System.Windows.Window]$Window, [System.Windows.Window]$Window,
@@ -54,7 +61,7 @@ function Get-PendingTweakActions {
$actions.Add([PSCustomObject]@{ $actions.Add([PSCustomObject]@{
Action = 'Undo' Action = 'Undo'
FeatureId = [string]$mapping.FeatureId FeatureId = [string]$mapping.FeatureId
Label = [string]$script:FeatureLabelLookup[$mapping.FeatureId] Label = [string](Get-UndoFeatureLabel -FeatureId $mapping.FeatureId)
}) })
} }
} }
+1 -7
View File
@@ -144,13 +144,7 @@ function Show-ApplyModal {
# Show completion message with reboot instructions if any applied features require reboot # Show completion message with reboot instructions if any applied features require reboot
if ($RestartExplorer) { if ($RestartExplorer) {
$rebootFeatures = @() $rebootFeatures = Get-RebootFeatureLabels
foreach ($paramKey in $script:Params.Keys) {
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) {
$feature = $script:Features[$paramKey]
$rebootFeatures += "$($feature.Label)"
}
}
if ($rebootFeatures.Count -gt 0) { if ($rebootFeatures.Count -gt 0) {
foreach ($featureName in $rebootFeatures) { foreach ($featureName in $rebootFeatures) {
@@ -0,0 +1,27 @@
<#
.SYNOPSIS
Resolves display labels for selected features that require reboot.
.DESCRIPTION
Combines parameter keys from both forward and undo selections, removes duplicates,
and returns the feature label that should be shown to users. Undo selections use
UndoLabel when available.
#>
function Get-RebootFeatureLabels {
$rebootFeatureLabels = [System.Collections.Generic.List[string]]::new()
$candidateParamKeys = (@($script:Params.Keys) + @($script:UndoParams.Keys)) | Select-Object -Unique
foreach ($paramKey in $candidateParamKeys) {
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) {
$feature = $script:Features[$paramKey]
$isUndo = $script:UndoParams.ContainsKey($paramKey)
$displayLabel = if ($isUndo -and $feature.UndoLabel) { $feature.UndoLabel } else { $feature.Label }
if (-not [string]::IsNullOrWhiteSpace([string]$displayLabel)) {
[void]$rebootFeatureLabels.Add([string]$displayLabel)
}
}
}
return $rebootFeatureLabels
}
+6 -1
View File
@@ -382,6 +382,7 @@ if (-not $script:WingetInstalled -and -not $Silent) {
. "$PSScriptRoot/Scripts/Helpers/GenerateAppsList.ps1" . "$PSScriptRoot/Scripts/Helpers/GenerateAppsList.ps1"
. "$PSScriptRoot/Scripts/Helpers/GetFriendlyRegistryBackupTarget.ps1" . "$PSScriptRoot/Scripts/Helpers/GetFriendlyRegistryBackupTarget.ps1"
. "$PSScriptRoot/Scripts/Helpers/GetFriendlyTargetUserName.ps1" . "$PSScriptRoot/Scripts/Helpers/GetFriendlyTargetUserName.ps1"
. "$PSScriptRoot/Scripts/Helpers/Get-RebootFeatureLabels.ps1"
. "$PSScriptRoot/Scripts/Helpers/ImportConfigToParams.ps1" . "$PSScriptRoot/Scripts/Helpers/ImportConfigToParams.ps1"
. "$PSScriptRoot/Scripts/Helpers/GetTargetUserForAppRemoval.ps1" . "$PSScriptRoot/Scripts/Helpers/GetTargetUserForAppRemoval.ps1"
. "$PSScriptRoot/Scripts/Helpers/Get-RegFileOperations.ps1" . "$PSScriptRoot/Scripts/Helpers/Get-RegFileOperations.ps1"
@@ -562,7 +563,11 @@ if (($controlParamsCount -eq $script:Params.Keys.Count) -or ($script:Params.Keys
# (This also handles restore point creation if requested) # (This also handles restore point creation if requested)
Invoke-AllChanges Invoke-AllChanges
RestartExplorer
# Restart Explorer process unless running in Sysprep or User context
if (-not ($script:Params.ContainsKey("Sysprep") -or $script:Params.ContainsKey("User"))) {
RestartExplorer
}
Write-Output "" Write-Output ""
Write-Output "" Write-Output ""