From 33b77f19a0bee3889ed48d98f51aa6b7554e91ef Mon Sep 17 00:00:00 2001 From: Jeffrey <9938813+Raphire@users.noreply.github.com> Date: Mon, 1 Jun 2026 22:53:28 +0200 Subject: [PATCH] Add confirmation dialogs & warning for Windows Terminal Removal Removal of this app can cause Win11Debloat to fail, if the script is launched via Windows Terminal --- Config/Apps.json | 4 +-- Config/Features.json | 14 ++++----- Scripts/GUI/Show-AppSelectionWindow.ps1 | 8 ++--- Scripts/GUI/Show-MainWindow.ps1 | 10 ++---- Scripts/Helpers/ConfirmUnsafeAppRemoval.ps1 | 34 +++++++++++++++++++++ Win11Debloat.ps1 | 1 + 6 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 Scripts/Helpers/ConfirmUnsafeAppRemoval.ps1 diff --git a/Config/Apps.json b/Config/Apps.json index 65e579f..9730a97 100644 --- a/Config/Apps.json +++ b/Config/Apps.json @@ -781,9 +781,9 @@ { "FriendlyName": "Windows Terminal", "AppId": "Microsoft.WindowsTerminal", - "Description": "Default terminal app in windows 11 (Command Prompt, PowerShell, WSL)", + "Description": "Default terminal app in windows 11 (Command Prompt, PowerShell, WSL), WARNING: Win11Debloat if it is launched via Windows Terminal.", "SelectedByDefault": false, - "Recommendation": "optional" + "Recommendation": "unsafe" }, { "FriendlyName": "Xbox TCUI Framework", diff --git a/Config/Features.json b/Config/Features.json index 0914012..d28769c 100644 --- a/Config/Features.json +++ b/Config/Features.json @@ -288,7 +288,7 @@ "Label": "Remove the apps specified with the 'Apps' parameter", "Category": null, "RegistryKey": null, - "ApplyText": null, + "ApplyText": "Removing selected apps...", "RegistryUndoKey": null, "MinVersion": null, "MaxVersion": null @@ -298,7 +298,7 @@ "Label": "The selection of apps to remove, specified as a comma separated list. Use 'Default' (or omit) to use the default apps list", "Category": null, "RegistryKey": null, - "ApplyText": null, + "ApplyText": "Removing selected apps...", "RegistryUndoKey": null, "MinVersion": null, "MaxVersion": null @@ -308,7 +308,7 @@ "Label": "Remove custom selection of apps", "Category": null, "RegistryKey": null, - "ApplyText": null, + "ApplyText": "Removing selected apps...", "RegistryUndoKey": null, "MinVersion": null, "MaxVersion": null @@ -318,7 +318,7 @@ "Label": "Remove the Mail, Calendar, and People apps", "Category": null, "RegistryKey": null, - "ApplyText": null, + "ApplyText": "Removing selected apps...", "RegistryUndoKey": null, "MinVersion": null, "MaxVersion": null @@ -328,7 +328,7 @@ "Label": "Remove the new Outlook for Windows app", "Category": null, "RegistryKey": null, - "ApplyText": null, + "ApplyText": "Removing selected apps...", "RegistryUndoKey": null, "MinVersion": null, "MaxVersion": null @@ -338,7 +338,7 @@ "Label": "Remove the Xbox App and Xbox Gamebar", "Category": null, "RegistryKey": null, - "ApplyText": null, + "ApplyText": "Removing selected apps...", "RegistryUndoKey": null, "MinVersion": null, "MaxVersion": null @@ -348,7 +348,7 @@ "Label": "Remove HP OEM applications", "Category": null, "RegistryKey": null, - "ApplyText": null, + "ApplyText": "Removing selected apps...", "RegistryUndoKey": null, "MinVersion": null, "MaxVersion": null diff --git a/Scripts/GUI/Show-AppSelectionWindow.ps1 b/Scripts/GUI/Show-AppSelectionWindow.ps1 index 43d22b0..5b86874 100644 --- a/Scripts/GUI/Show-AppSelectionWindow.ps1 +++ b/Scripts/GUI/Show-AppSelectionWindow.ps1 @@ -130,12 +130,8 @@ function Show-AppSelectionWindow { return } - if ($selectedApps -contains "Microsoft.WindowsStore" -and -not $Silent) { - $result = Show-MessageBox -Message 'Are you sure you wish to uninstall the Microsoft Store? This app cannot easily be reinstalled.' -Title 'Are you sure?' -Button 'YesNo' -Icon 'Warning' -Owner $window - - if ($result -eq 'No') { - return - } + if (-not (ConfirmUnsafeAppRemoval -SelectedApps $selectedApps -Owner $window)) { + return } SaveCustomAppsListToFile -appsList $selectedApps diff --git a/Scripts/GUI/Show-MainWindow.ps1 b/Scripts/GUI/Show-MainWindow.ps1 index d4bff0f..0f8491b 100644 --- a/Scripts/GUI/Show-MainWindow.ps1 +++ b/Scripts/GUI/Show-MainWindow.ps1 @@ -1773,15 +1773,11 @@ function Show-MainWindow { $selectedApps = @($selectedApps | Where-Object { $_ } | Select-Object -Unique) if ($selectedApps.Count -gt 0) { - # Check if Microsoft Store is selected - if ($selectedApps -contains "Microsoft.WindowsStore") { - $result = Show-MessageBox -Message 'Are you sure you wish to uninstall the Microsoft Store? This app cannot easily be reinstalled.' -Title 'Are you sure?' -Button 'YesNo' -Icon 'Warning' - - if ($result -eq 'No') { - return - } + if (-not (ConfirmUnsafeAppRemoval -SelectedApps $selectedApps -Owner $window)) { + return } + AddParameter 'RemoveApps' AddParameter 'Apps' ($selectedApps -join ',') diff --git a/Scripts/Helpers/ConfirmUnsafeAppRemoval.ps1 b/Scripts/Helpers/ConfirmUnsafeAppRemoval.ps1 new file mode 100644 index 0000000..6203357 --- /dev/null +++ b/Scripts/Helpers/ConfirmUnsafeAppRemoval.ps1 @@ -0,0 +1,34 @@ +# Shows confirmation dialogs for apps that require extra caution before removal. +# Returns $true if the user confirmed all warnings (or if no warnings were triggered), +# $false if the user declined any warning. +function ConfirmUnsafeAppRemoval { + param ( + [string[]]$SelectedApps, + $Owner = $null + ) + + # Skip all warnings in Silent mode + if ($Silent) { + return $true + } + + # Microsoft Store warning + if ($SelectedApps -contains "Microsoft.WindowsStore") { + $result = Show-MessageBox -Message 'Are you sure that you wish to uninstall the Microsoft Store? This app cannot easily be reinstalled.' -Title 'Are you sure?' -Button 'YesNo' -Icon 'Warning' -Owner $Owner + + if ($result -eq 'No') { + return $false + } + } + + # Windows Terminal warning + if ($SelectedApps -contains "Microsoft.WindowsTerminal") { + $result = Show-MessageBox -Message 'Are you sure that you wish to remove Windows Terminal? Windows Terminal is the default command-line app for Windows. Ensure you are not running Win11Debloat via Windows Terminal before proceeding to avoid a mid-process failure.' -Title 'Are you sure?' -Button 'YesNo' -Icon 'Warning' -Owner $Owner + + if ($result -eq 'No') { + return $false + } + } + + return $true +} \ No newline at end of file diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index 2b58f8b..2171521 100644 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -351,6 +351,7 @@ if (-not $script:WingetInstalled -and -not $Silent) { . "$PSScriptRoot/Scripts/Helpers/RegistryPathHelpers.ps1" . "$PSScriptRoot/Scripts/Helpers/ApplyRegistryRegFile.ps1" . "$PSScriptRoot/Scripts/Helpers/TestIfUserIsLoggedIn.ps1" +. "$PSScriptRoot/Scripts/Helpers/ConfirmUnsafeAppRemoval.ps1" # Threading functions . "$PSScriptRoot/Scripts/Threading/DoEvents.ps1"