Refactor code structure for improved readability and maintainability (#473)

* Add ToolTips to Tweaks
This commit is contained in:
Jeffrey
2026-02-15 23:08:54 +01:00
committed by GitHub
parent 95dc490b6e
commit 65aabbc050
31 changed files with 2877 additions and 2813 deletions

View File

@@ -0,0 +1,20 @@
# Prints the header for the script
function PrintHeader {
param (
$title
)
$fullTitle = " Win11Debloat Script - $title"
if ($script:Params.ContainsKey("Sysprep")) {
$fullTitle = "$fullTitle (Sysprep mode)"
}
else {
$fullTitle = "$fullTitle (User: $(GetUserName))"
}
Clear-Host
Write-Host "-------------------------------------------------------------------------------------------"
Write-Host $fullTitle
Write-Host "-------------------------------------------------------------------------------------------"
}

View File

@@ -0,0 +1,66 @@
# Prints all pending changes that will be made by the script
function PrintPendingChanges {
Write-Output "Win11Debloat will make the following changes:"
if ($script:Params['CreateRestorePoint']) {
Write-Output "- $($script:Features['CreateRestorePoint'].Label)"
}
foreach ($parameterName in $script:Params.Keys) {
if ($script:ControlParams -contains $parameterName) {
continue
}
# Print parameter description
switch ($parameterName) {
'Apps' {
continue
}
'CreateRestorePoint' {
continue
}
'RemoveApps' {
$appsList = GenerateAppsList
if ($appsList.Count -eq 0) {
Write-Host "No valid apps were selected for removal" -ForegroundColor Yellow
Write-Output ""
continue
}
Write-Output "- Remove $($appsList.Count) apps:"
Write-Host $appsList -ForegroundColor DarkGray
continue
}
'RemoveAppsCustom' {
$appsList = LoadAppsFromFile $script:CustomAppsListFilePath
if ($appsList.Count -eq 0) {
Write-Host "No valid apps were selected for removal" -ForegroundColor Yellow
Write-Output ""
continue
}
Write-Output "- Remove $($appsList.Count) apps:"
Write-Host $appsList -ForegroundColor DarkGray
continue
}
default {
if ($script:Features -and $script:Features.ContainsKey($parameterName)) {
$action = $script:Features[$parameterName].Action
$message = $script:Features[$parameterName].Label
Write-Output "- $action $message"
}
else {
# Fallback: show the parameter name if no feature description is available
Write-Output "- $parameterName"
}
continue
}
}
}
Write-Output ""
Write-Output ""
Write-Output "Press enter to execute the script or press CTRL+C to quit..."
Read-Host | Out-Null
}

View File

@@ -0,0 +1,28 @@
# Shows the CLI app removal menu and prompts the user to select which apps to remove.
function ShowCLIAppRemoval {
PrintHeader "App Removal"
Write-Output "> Opening app selection form..."
$result = Show-AppSelectionWindow
if ($result -eq $true) {
Write-Output "You have selected $($script:SelectedApps.Count) apps for removal"
AddParameter 'RemoveAppsCustom'
SaveSettings
# Suppress prompt if Silent parameter was passed
if (-not $Silent) {
Write-Output ""
Write-Output ""
Write-Output "Press enter to remove the selected apps or press CTRL+C to quit..."
Read-Host | Out-Null
PrintHeader "App Removal"
}
}
else {
Write-Host "Selection was cancelled, no apps have been removed" -ForegroundColor Red
Write-Output ""
}
}

View File

@@ -0,0 +1,33 @@
# Shows the CLI default mode app removal options. Loops until a valid option is selected.
function ShowCLIDefaultModeAppRemovalOptions {
PrintHeader 'Default Mode'
Write-Host "Please note: The default selection of apps includes Microsoft Teams, Spotify, Sticky Notes and more. Select option 2 to verify and change what apps are removed by the script" -ForegroundColor DarkGray
Write-Host ""
Do {
Write-Host "Options:" -ForegroundColor Yellow
Write-Host " (n) Don't remove any apps" -ForegroundColor Yellow
Write-Host " (1) Only remove the default selection of apps" -ForegroundColor Yellow
Write-Host " (2) Manually select which apps to remove" -ForegroundColor Yellow
$RemoveAppsInput = Read-Host "Do you want to remove any apps? Apps will be removed for all users (n/1/2)"
# Show app selection form if user entered option 3
if ($RemoveAppsInput -eq '2') {
$result = Show-AppSelectionWindow
if ($result -ne $true) {
# User cancelled or closed app selection, change RemoveAppsInput so the menu will be shown again
Write-Host ""
Write-Host "Cancelled application selection, please try again" -ForegroundColor Red
$RemoveAppsInput = 'c'
}
Write-Host ""
}
}
while ($RemoveAppsInput -ne 'n' -and $RemoveAppsInput -ne '0' -and $RemoveAppsInput -ne '1' -and $RemoveAppsInput -ne '2')
return $RemoveAppsInput
}

View File

@@ -0,0 +1,55 @@
# Show CLI default mode options for removing apps, or set selection if RunDefaults or RunDefaultsLite parameter was passed
function ShowCLIDefaultModeOptions {
if ($RunDefaults) {
$RemoveAppsInput = '1'
}
elseif ($RunDefaultsLite) {
$RemoveAppsInput = '0'
}
else {
$RemoveAppsInput = ShowCLIDefaultModeAppRemovalOptions
if ($RemoveAppsInput -eq '2' -and ($script:SelectedApps.contains('Microsoft.XboxGameOverlay') -or $script:SelectedApps.contains('Microsoft.XboxGamingOverlay')) -and
$( Read-Host -Prompt "Disable Game Bar integration and game/screen recording? This also stops ms-gamingoverlay and ms-gamebar popups (y/n)" ) -eq 'y') {
$DisableGameBarIntegrationInput = $true;
}
}
PrintHeader 'Default Mode'
# Add default settings based on user input
try {
# Select app removal options based on user input
switch ($RemoveAppsInput) {
'1' {
AddParameter 'RemoveApps'
AddParameter 'Apps' 'Default'
}
'2' {
AddParameter 'RemoveAppsCustom'
if ($DisableGameBarIntegrationInput) {
AddParameter 'DisableDVR'
AddParameter 'DisableGameBarIntegration'
}
}
}
# Load settings from DefaultSettings.json and add to params
LoadSettings -filePath $script:DefaultSettingsFilePath -expectedVersion "1.0"
}
catch {
Write-Error "Failed to load settings from DefaultSettings.json file: $_"
AwaitKeyToExit
}
SaveSettings
# Skip change summary if Silent parameter was passed
if ($Silent) {
return
}
PrintPendingChanges
PrintHeader 'Default Mode'
}

View File

@@ -0,0 +1,16 @@
# Shows the CLI last used settings from LastUsedSettings.json file, displays pending changes and prompts the user to apply them.
function ShowCLILastUsedSettings {
PrintHeader 'Custom Mode'
try {
# Load settings from LastUsedSettings.json and add to params
LoadSettings -filePath $script:SavedSettingsFilePath -expectedVersion "1.0"
}
catch {
Write-Error "Failed to load settings from LastUsedSettings.json file: $_"
AwaitKeyToExit
}
PrintPendingChanges
PrintHeader 'Custom Mode'
}

View File

@@ -0,0 +1,30 @@
# Shows the CLI menu options and prompts the user to select one. Loops until a valid option is selected.
function ShowCLIMenuOptions {
Do {
$ModeSelectionMessage = "Please select an option (1/2)"
PrintHeader 'Menu'
Write-Host "(1) Default mode: Quickly apply the recommended changes"
Write-Host "(2) App removal mode: Select & remove apps, without making other changes"
# Only show this option if SavedSettings file exists
if (Test-Path $script:SavedSettingsFilePath) {
Write-Host "(3) Quickly apply your last used settings"
$ModeSelectionMessage = "Please select an option (1/2/3)"
}
Write-Host ""
Write-Host ""
$Mode = Read-Host $ModeSelectionMessage
if (($Mode -eq '3') -and -not (Test-Path $script:SavedSettingsFilePath)) {
$Mode = $null
}
}
while ($Mode -ne '1' -and $Mode -ne '2' -and $Mode -ne '3')
return $Mode
}