From 3b78e8d4ed2e8ade9a5fb99befb0afbfd78a3489 Mon Sep 17 00:00:00 2001 From: Jeffrey <9938813+Raphire@users.noreply.github.com> Date: Sat, 11 Jul 2026 20:04:51 +0200 Subject: [PATCH] Fix: Show reboot warning for undoing features that require it (#699) --- Scripts/Features/RestartExplorer.ps1 | 21 ++++++++-------- Scripts/GUI/MainWindow-Deployment.ps1 | 9 ++++++- Scripts/GUI/Show-ApplyModal.ps1 | 8 +----- Scripts/Helpers/Get-RebootFeatureLabels.ps1 | 27 +++++++++++++++++++++ Win11Debloat.ps1 | 7 +++++- 5 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 Scripts/Helpers/Get-RebootFeatureLabels.ps1 diff --git a/Scripts/Features/RestartExplorer.ps1 b/Scripts/Features/RestartExplorer.ps1 index b6c7da1..c5cb510 100644 --- a/Scripts/Features/RestartExplorer.ps1 +++ b/Scripts/Features/RestartExplorer.ps1 @@ -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. diff --git a/Scripts/GUI/MainWindow-Deployment.ps1 b/Scripts/GUI/MainWindow-Deployment.ps1 index e5b990c..34b5cb5 100644 --- a/Scripts/GUI/MainWindow-Deployment.ps1 +++ b/Scripts/GUI/MainWindow-Deployment.ps1 @@ -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) }) } } diff --git a/Scripts/GUI/Show-ApplyModal.ps1 b/Scripts/GUI/Show-ApplyModal.ps1 index aaa3a36..7985d8a 100644 --- a/Scripts/GUI/Show-ApplyModal.ps1 +++ b/Scripts/GUI/Show-ApplyModal.ps1 @@ -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) { diff --git a/Scripts/Helpers/Get-RebootFeatureLabels.ps1 b/Scripts/Helpers/Get-RebootFeatureLabels.ps1 new file mode 100644 index 0000000..c5ab73f --- /dev/null +++ b/Scripts/Helpers/Get-RebootFeatureLabels.ps1 @@ -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 +} \ No newline at end of file diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index aece5e4..83ffaea 100644 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -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 -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 ""