Add warning about some changes requiring a reboot & fix focus loss after Explorer restart (#506)

This commit is contained in:
Jeffrey
2026-03-07 15:53:58 +01:00
committed by GitHub
parent 8956c41b4d
commit c72e4fcb54
5 changed files with 94 additions and 22 deletions

View File

@@ -702,6 +702,7 @@
"ApplyText": "Turning off Enhanced Pointer Precision...",
"UndoAction": "Enable",
"RegistryUndoKey": "Enable_Enhance_Pointer_Precision.reg",
"RequiresReboot": true,
"MinVersion": null,
"MaxVersion": null
},
@@ -715,6 +716,7 @@
"ApplyText": "Disabling the Sticky Keys keyboard shortcut...",
"UndoAction": "Enable",
"RegistryUndoKey": "Enable_Sticky_Keys_Shortcut.reg",
"RequiresReboot": true,
"MinVersion": 26100,
"MaxVersion": null
},
@@ -1236,6 +1238,7 @@
"ApplyText": "Disabling animations and visual effects...",
"UndoAction": "Enable",
"RegistryUndoKey": "Enable_Animations.reg",
"RequiresReboot": true,
"MinVersion": null,
"MaxVersion": null
},
@@ -1391,6 +1394,7 @@
"ApplyText": "Enabling Windows Sandbox...",
"UndoAction": null,
"RegistryUndoKey": null,
"RequiresReboot": true,
"MinVersion": 22483,
"MaxVersion": null
},
@@ -1404,6 +1408,7 @@
"ApplyText": "Enabling Windows Subsystem for Linux...",
"UndoAction": null,
"RegistryUndoKey": null,
"RequiresReboot": true,
"MinVersion": 22000,
"MaxVersion": null
}

View File

@@ -141,10 +141,35 @@
Style="{DynamicResource ModalTitleStyle}"/>
<TextBlock x:Name="ApplyCompletionMessage"
Text="Your clean system is ready. Thanks for using Win11Debloat!"
Text="Please note that some changes will only take effect after a reboot. Thanks for using Win11Debloat!"
TextWrapping="Wrap"
Style="{DynamicResource ModalSubtextStyle}"/>
</StackPanel>
<!-- Reboot required section -->
<Border x:Name="ApplyRebootPanel"
Visibility="Collapsed"
BorderBrush="{DynamicResource BorderColor}"
BorderThickness="0,1,0,1"
Padding="24,12,24,14">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,6">
<TextBlock Text="&#xE7BA;"
FontFamily="Segoe Fluent Icons"
FontSize="14"
Foreground="#e8912d"
VerticalAlignment="Center"
Margin="0,0,8,0"/>
<TextBlock Text="A restart is required for these changes to take effect:"
FontSize="13"
FontWeight="SemiBold"
Foreground="{DynamicResource FgColor}"
VerticalAlignment="Center"/>
</StackPanel>
<StackPanel x:Name="ApplyRebootList" Margin="22,0,0,0"/>
</StackPanel>
</Border>
<!-- Button Panel -->
<Border Background="{DynamicResource BgColor}"
BorderBrush="{DynamicResource BorderColor}"

View File

@@ -8,6 +8,26 @@ function Show-ApplyModal {
Add-Type -AssemblyName PresentationFramework,PresentationCore,WindowsBase | Out-Null
# P/Invoke helpers for forcing focus back after Explorer restart
if (-not ([System.Management.Automation.PSTypeName]'Win11Debloat.FocusHelper').Type) {
Add-Type -Namespace Win11Debloat -Name FocusHelper -MemberDefinition @'
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr lpdwProcessId);
[DllImport("user32.dll")] public static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);
[DllImport("kernel32.dll")] public static extern uint GetCurrentThreadId();
public static void ForceActivate(IntPtr hwnd) {
IntPtr fg = GetForegroundWindow();
uint fgThread = GetWindowThreadProcessId(fg, IntPtr.Zero);
uint myThread = GetCurrentThreadId();
if (fgThread != myThread) AttachThreadInput(myThread, fgThread, true);
SetForegroundWindow(hwnd);
if (fgThread != myThread) AttachThreadInput(myThread, fgThread, false);
}
'@
}
$usesDarkMode = GetSystemUsesDarkMode
# Determine owner window
@@ -55,6 +75,8 @@ function Show-ApplyModal {
$script:ApplyCompletionTitleEl = $applyWindow.FindName('ApplyCompletionTitle')
$script:ApplyCompletionMessageEl = $applyWindow.FindName('ApplyCompletionMessage')
$script:ApplyCompletionIconEl = $applyWindow.FindName('ApplyCompletionIcon')
$applyRebootPanel = $applyWindow.FindName('ApplyRebootPanel')
$applyRebootList = $applyWindow.FindName('ApplyRebootList')
$applyCloseBtn = $applyWindow.FindName('ApplyCloseBtn')
$applyKofiBtn = $applyWindow.FindName('ApplyKofiBtn')
$applyCancelBtn = $applyWindow.FindName('ApplyCancelBtn')
@@ -104,6 +126,13 @@ function Show-ApplyModal {
# Restart explorer if requested
if ($RestartExplorer -and -not $script:CancelRequested) {
RestartExplorer
# Wait for Explorer to finish relaunching, then reclaim focus.
Start-Sleep -Milliseconds 800
$applyWindow.Dispatcher.Invoke([action]{
$hwnd = (New-Object System.Windows.Interop.WindowInteropHelper($applyWindow)).Handle
[Win11Debloat.FocusHelper]::ForceActivate($hwnd)
})
}
Write-Host ""
@@ -125,8 +154,34 @@ function Show-ApplyModal {
$script:ApplyCompletionMessageEl.Text = "Script execution was cancelled by the user."
} else {
$script:ApplyCompletionTitleEl.Text = "Changes Applied"
# 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.Action) $($feature.Label)"
}
}
if ($rebootFeatures.Count -gt 0) {
foreach ($featureName in $rebootFeatures) {
$tb = [System.Windows.Controls.TextBlock]::new()
$tb.Text = "$([char]0x2022) $featureName"
$tb.FontSize = 12
$tb.SetResourceReference([System.Windows.Controls.TextBlock]::ForegroundProperty, 'FgColor')
$tb.Opacity = 0.85
$tb.Margin = [System.Windows.Thickness]::new(0, 2, 0, 0)
$applyRebootList.Children.Add($tb) | Out-Null
}
$applyRebootPanel.Visibility = 'Visible'
}
else {
$script:ApplyCompletionMessageEl.Text = "Your clean system is ready. Thanks for using Win11Debloat!"
}
}
}
$applyWindow.Dispatcher.Invoke([System.Windows.Threading.DispatcherPriority]::Render, [action]{})
}
catch {

View File

@@ -1203,7 +1203,7 @@ function Show-MainWindow {
return
}
$message = ($changesList | ForEach-Object { "- $_" }) -join "`n"
$message = ($changesList | ForEach-Object { "$([char]0x2022) $_" }) -join "`n"
Show-MessageBox -Message $message -Title 'Selected Changes' -Button 'OK' -Icon 'None' -Width 600
}

View File

@@ -1146,24 +1146,11 @@ function RestartExplorer {
return
}
if ($script:Params.ContainsKey("EnableWindowsSandbox")) {
Write-Host "Warning: The Windows Sandbox feature will only be available after a reboot" -ForegroundColor Yellow
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.Action) $($feature.Label)' requires a reboot to take full effect" -ForegroundColor Yellow
}
if ($script:Params.ContainsKey("EnableWindowsSubsystemForLinux")) {
Write-Host "Warning: The Windows Subsystem for Linux feature will only be available after a reboot" -ForegroundColor Yellow
}
if ($script:Params.ContainsKey("DisableMouseAcceleration")) {
Write-Host "Warning: Changes to the Enhance Pointer Precision setting will only take effect after a reboot" -ForegroundColor Yellow
}
if ($script:Params.ContainsKey("DisableStickyKeys")) {
Write-Host "Warning: Changes to the Sticky Keys setting will only take effect after a reboot" -ForegroundColor Yellow
}
if ($script:Params.ContainsKey("DisableAnimations")) {
Write-Host "Warning: Animations will only be disabled after a reboot" -ForegroundColor Yellow
}
# Only restart if the powershell process matches the OS architecture.