mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-04-03 14:06:27 +00:00
Improve app page with sorting, recommendations and more (#520)
This commit is contained in:
@@ -11,60 +11,64 @@ function ApplySettingsToUiControls {
|
||||
return $false
|
||||
}
|
||||
|
||||
# First, reset all tweaks to "No Change" (index 0) or unchecked
|
||||
if ($uiControlMappings) {
|
||||
foreach ($comboName in $uiControlMappings.Keys) {
|
||||
$control = $window.FindName($comboName)
|
||||
if ($control -is [System.Windows.Controls.CheckBox]) {
|
||||
$control.IsChecked = $false
|
||||
}
|
||||
elseif ($control -is [System.Windows.Controls.ComboBox]) {
|
||||
$control.SelectedIndex = 0
|
||||
if (-not $uiControlMappings) {
|
||||
return $true
|
||||
}
|
||||
|
||||
# Build control cache and reverse index (featureId -> control info) in a single pass
|
||||
$controlCache = @{}
|
||||
$featureIdIndex = @{}
|
||||
|
||||
foreach ($comboName in $uiControlMappings.Keys) {
|
||||
$control = $window.FindName($comboName)
|
||||
if (-not $control) { continue }
|
||||
$controlCache[$comboName] = $control
|
||||
|
||||
$mapping = $uiControlMappings[$comboName]
|
||||
if ($mapping.Type -eq 'group') {
|
||||
$i = 1
|
||||
foreach ($val in $mapping.Values) {
|
||||
foreach ($fid in $val.FeatureIds) {
|
||||
$featureIdIndex[$fid] = @{ ComboName = $comboName; Control = $control; Index = $i; MappingType = 'group' }
|
||||
}
|
||||
$i++
|
||||
}
|
||||
}
|
||||
elseif ($mapping.Type -eq 'feature') {
|
||||
$featureIdIndex[$mapping.FeatureId] = @{ ComboName = $comboName; Control = $control; MappingType = 'feature' }
|
||||
}
|
||||
|
||||
# Reset control to default state
|
||||
if ($control -is [System.Windows.Controls.CheckBox]) {
|
||||
$control.IsChecked = $false
|
||||
}
|
||||
elseif ($control -is [System.Windows.Controls.ComboBox]) {
|
||||
$control.SelectedIndex = 0
|
||||
}
|
||||
}
|
||||
|
||||
# Apply settings from JSON
|
||||
# Apply settings using O(1) lookups
|
||||
foreach ($setting in $settingsJson.Settings) {
|
||||
if ($setting.Value -ne $true) { continue }
|
||||
$paramName = $setting.Name
|
||||
if ($setting.Name -eq 'CreateRestorePoint') { continue }
|
||||
|
||||
# Skip RestorePointCheckBox, this is always checked by default
|
||||
if ($paramName -eq 'CreateRestorePoint') {
|
||||
continue
|
||||
$entry = $featureIdIndex[$setting.Name]
|
||||
if (-not $entry) { continue }
|
||||
|
||||
$control = $entry.Control
|
||||
if (-not $control -or $control.Visibility -ne 'Visible') { continue }
|
||||
|
||||
if ($entry.MappingType -eq 'group') {
|
||||
if ($control -is [System.Windows.Controls.ComboBox]) {
|
||||
$control.SelectedIndex = $entry.Index
|
||||
}
|
||||
}
|
||||
|
||||
if ($uiControlMappings) {
|
||||
foreach ($comboName in $uiControlMappings.Keys) {
|
||||
$mapping = $uiControlMappings[$comboName]
|
||||
if ($mapping.Type -eq 'group') {
|
||||
$i = 1
|
||||
foreach ($val in $mapping.Values) {
|
||||
if ($val.FeatureIds -contains $paramName) {
|
||||
$control = $window.FindName($comboName)
|
||||
if ($control -and $control.Visibility -eq 'Visible') {
|
||||
if ($control -is [System.Windows.Controls.ComboBox]) {
|
||||
$control.SelectedIndex = $i
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
$i++
|
||||
}
|
||||
}
|
||||
elseif ($mapping.Type -eq 'feature') {
|
||||
if ($mapping.FeatureId -eq $paramName) {
|
||||
$control = $window.FindName($comboName)
|
||||
if ($control -and $control.Visibility -eq 'Visible') {
|
||||
if ($control -is [System.Windows.Controls.CheckBox]) {
|
||||
$control.IsChecked = $true
|
||||
}
|
||||
elseif ($control -is [System.Windows.Controls.ComboBox]) {
|
||||
$control.SelectedIndex = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($control -is [System.Windows.Controls.CheckBox]) {
|
||||
$control.IsChecked = $true
|
||||
}
|
||||
elseif ($control -is [System.Windows.Controls.ComboBox]) {
|
||||
$control.SelectedIndex = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user