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 {
# Restarting Explorer while running in Sysprep or User context is not necessary
if ($script:Params.ContainsKey("Sysprep") -or $script:Params.ContainsKey("User")) {
return
}
<#
.SYNOPSIS
Restarts Windows Explorer to apply system changes.
.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")) {
Write-Host "[WhatIf] Restart the Windows Explorer process" -ForegroundColor Cyan
return
@@ -17,11 +18,9 @@ function RestartExplorer {
return
}
foreach ($paramKey in $script:Params.Keys) {
if ($script:Features.ContainsKey($paramKey) -and $script:Features[$paramKey].RequiresReboot -eq $true) {
$feature = $script:Features[$paramKey]
Write-Host "Warning: '$($feature.Label)' requires a reboot to take full effect" -ForegroundColor Yellow
}
$rebootFeatures = Get-RebootFeatureLabels
foreach ($displayLabel in $rebootFeatures) {
Write-Host "Warning: '$displayLabel' requires a reboot to take full effect" -ForegroundColor Yellow
}
# 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]
}
<#
.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 {
param(
[System.Windows.Window]$Window,
@@ -54,7 +61,7 @@ function Get-PendingTweakActions {
$actions.Add([PSCustomObject]@{
Action = 'Undo'
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
if ($RestartExplorer) {
$rebootFeatures = @()
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)"
}
}
$rebootFeatures = Get-RebootFeatureLabels
if ($rebootFeatures.Count -gt 0) {
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
}
+5
View File
@@ -382,6 +382,7 @@ if (-not $script:WingetInstalled -and -not $Silent) {
. "$PSScriptRoot/Scripts/Helpers/GenerateAppsList.ps1"
. "$PSScriptRoot/Scripts/Helpers/GetFriendlyRegistryBackupTarget.ps1"
. "$PSScriptRoot/Scripts/Helpers/GetFriendlyTargetUserName.ps1"
. "$PSScriptRoot/Scripts/Helpers/Get-RebootFeatureLabels.ps1"
. "$PSScriptRoot/Scripts/Helpers/ImportConfigToParams.ps1"
. "$PSScriptRoot/Scripts/Helpers/GetTargetUserForAppRemoval.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)
Invoke-AllChanges
# 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 ""