Fix: Respect Feature min/max version for comboboxes (#639)

This commit is contained in:
Jeffrey
2026-06-19 18:20:25 +02:00
committed by GitHub
parent c039b04717
commit 535b62db40
2 changed files with 65 additions and 6 deletions

View File

@@ -1082,8 +1082,8 @@
"Category": "Taskbar", "Category": "Taskbar",
"RegistryKey": "Combine_Taskbar_Always.reg", "RegistryKey": "Combine_Taskbar_Always.reg",
"ApplyText": "Setting the taskbar on the main display to always combine buttons and hide labels", "ApplyText": "Setting the taskbar on the main display to always combine buttons and hide labels",
"UndoLabel": "Use default taskbar combine behavior", "UndoLabel": null,
"ApplyUndoText": "Resetting the taskbar on the main display to always combine buttons and hide labels", "ApplyUndoText": null,
"RegistryUndoKey": null, "RegistryUndoKey": null,
"MinVersion": 22000, "MinVersion": 22000,
"MaxVersion": null "MaxVersion": null
@@ -1094,8 +1094,8 @@
"Category": "Taskbar", "Category": "Taskbar",
"RegistryKey": "Combine_MMTaskbar_Always.reg", "RegistryKey": "Combine_MMTaskbar_Always.reg",
"ApplyText": "Setting the taskbar on secondary displays to always combine buttons and hide labels", "ApplyText": "Setting the taskbar on secondary displays to always combine buttons and hide labels",
"UndoLabel": "Use default taskbar combine behavior", "UndoLabel": null,
"ApplyUndoText": "Resetting the taskbar on secondary displays to always combine buttons and hide labels", "ApplyUndoText": null,
"RegistryUndoKey": null, "RegistryUndoKey": null,
"MinVersion": 22000, "MinVersion": 22000,
"MaxVersion": null "MaxVersion": null

View File

@@ -192,6 +192,12 @@ function Build-DynamicTweaks {
} }
} }
# Build a FeatureId -> feature lookup for version filtering in groups
$featureMap = @{}
foreach ($f in $featuresJson.Features) {
$featureMap[$f.FeatureId] = $f
}
foreach ($categoryObj in $orderedCategories) { foreach ($categoryObj in $orderedCategories) {
$categoryName = $categoryObj.Name $categoryName = $categoryObj.Name
@@ -250,7 +256,60 @@ function Build-DynamicTweaks {
foreach ($item in $sortedItems) { foreach ($item in $sortedItems) {
if ($item.Type -eq 'group') { if ($item.Type -eq 'group') {
$group = $item.Data $group = $item.Data
$items = @('No Change') + ($group.Values | ForEach-Object { $_.Label }) # Filter values by Windows version compatibility of their referenced features
$filteredValues = @($group.Values | Where-Object {
$allCompatible = $true
foreach ($fid in $_.FeatureIds) {
if ($featureMap.ContainsKey($fid)) {
$f = $featureMap[$fid]
if (($f.MinVersion -and $WinVersion -lt $f.MinVersion) -or ($f.MaxVersion -and $WinVersion -gt $f.MaxVersion)) {
$allCompatible = $false
break
}
}
}
$allCompatible
})
# Skip the group entirely if all values are incompatible with this Windows version
if ($filteredValues.Count -eq 0) { continue }
# When only 1 value remains, render as the underlying feature directly
if ($filteredValues.Count -eq 1) {
$featureIds = $filteredValues[0].FeatureIds
if (-not $featureIds -or $featureIds.Count -eq 0) { continue }
$soleFid = $featureIds[0]
if ($featureMap.ContainsKey($soleFid)) {
$soleFeature = $featureMap[$soleFid]
$opt = 'Apply'
if ($soleFeature.FeatureId -match '^Disable') { $opt = 'Disable' } elseif ($soleFeature.FeatureId -match '^Enable') { $opt = 'Enable' }
$items = @('No Change', $opt)
$comboName = ("Feature_{0}_Combo" -f $soleFeature.FeatureId) -replace '[^a-zA-Z0-9_]', ''
$combo = CreateLabeledCombo -parent $panel -labelText $soleFeature.Label -comboName $comboName -items $items
# attach tooltip from Features.json if present
if ($soleFeature.ToolTip -or $soleFeature.DisableWhenApplied -eq $true) {
$tooltipText = $soleFeature.ToolTip
if ($soleFeature.DisableWhenApplied -eq $true) {
$tooltipText = "This tweak is already applied and cannot be undone automatically. Visit the Win11Debloat wiki for instructions on how to manually revert this change."
}
$tipBlock = New-Object System.Windows.Controls.TextBlock
$tipBlock.Text = $tooltipText
$tipBlock.TextWrapping = 'Wrap'
$tipBlock.MaxWidth = 420
$combo.ToolTip = $tipBlock
[System.Windows.Controls.ToolTipService]::SetShowOnDisabled($combo, $true)
$lblBorderObj = $null
try { $lblBorderObj = $Window.FindName("$comboName`_LabelBorder") } catch {}
if ($lblBorderObj) { $lblBorderObj.ToolTip = $tipBlock }
}
$script:UiControlMappings[$comboName] = @{ Type = 'feature'; FeatureId = $soleFeature.FeatureId; Label = $soleFeature.Label; Category = $categoryName }
}
continue
}
$items = @('No Change') + ($filteredValues | ForEach-Object { $_.Label })
$comboName = 'Group_{0}Combo' -f $group.GroupId $comboName = 'Group_{0}Combo' -f $group.GroupId
$combo = CreateLabeledCombo -parent $panel -labelText $group.Label -comboName $comboName -items $items $combo = CreateLabeledCombo -parent $panel -labelText $group.Label -comboName $comboName -items $items
# attach tooltip from UiGroups if present # attach tooltip from UiGroups if present
@@ -264,7 +323,7 @@ function Build-DynamicTweaks {
try { $lblBorderObj = $Window.FindName("$comboName`_LabelBorder") } catch {} try { $lblBorderObj = $Window.FindName("$comboName`_LabelBorder") } catch {}
if ($lblBorderObj) { $lblBorderObj.ToolTip = $tipBlock } if ($lblBorderObj) { $lblBorderObj.ToolTip = $tipBlock }
} }
$script:UiControlMappings[$comboName] = @{ Type = 'group'; Values = $group.Values; Label = $group.Label; Category = $categoryName } $script:UiControlMappings[$comboName] = @{ Type = 'group'; Values = $filteredValues; Label = $group.Label; Category = $categoryName }
} }
elseif ($item.Type -eq 'feature') { elseif ($item.Type -eq 'feature') {
$feature = $item.Data $feature = $item.Data