Refactor UI checkbox and toggle state synchronization (#4885)

Co-authored-by: vyas-devgna <vyas-devgna@users.noreply.github.com>
This commit is contained in:
Vyas Devgna
2026-08-03 11:38:26 -05:00
committed by GitHub
co-authored by vyas-devgna
parent 1ef581026f
commit 91ffd3af30
+7 -24
View File
@@ -20,28 +20,12 @@ function Reset-WPFCheckBoxes {
[Parameter(position=1)] [Parameter(position=1)]
[string]$checkboxfilterpattern = "**" [string]$checkboxfilterpattern = "**"
) )
$selectedSet = [System.Collections.Generic.HashSet[string]]::new([string[]]@($sync.selectedApps + $sync.selectedTweaks + $sync.selectedFeatures + $sync.selectedAppx), [StringComparer]::OrdinalIgnoreCase)
$CheckBoxesToCheck = $sync.selectedApps + $sync.selectedTweaks + $sync.selectedFeatures + $sync.selectedAppx foreach ($syncEntry in $sync.GetEnumerator()) {
$CheckBoxes = foreach ($syncEntry in $sync.GetEnumerator()) {
if ($syncEntry.Value -is [System.Windows.Controls.CheckBox] -and $syncEntry.Name -notlike "WPFToggle*" -and $syncEntry.Name -like $checkboxfilterpattern) { if ($syncEntry.Value -is [System.Windows.Controls.CheckBox] -and $syncEntry.Name -notlike "WPFToggle*" -and $syncEntry.Name -like $checkboxfilterpattern) {
$syncEntry $checkboxName = $syncEntry.Key
} $sync.$checkboxName.IsChecked = $selectedSet.Contains($checkboxName)
}
foreach ($CheckBox in $CheckBoxes) {
$checkboxName = $CheckBox.Key
if (-not $CheckBoxesToCheck) {
$sync.$checkBoxName.IsChecked = $false
continue
}
# Check if the checkbox name exists in the flattened JSON hashtable
if ($CheckBoxesToCheck -contains $checkboxName) {
# If it exists, set IsChecked to true
$sync.$checkboxName.IsChecked = $true
} else {
# If it doesn't exist, set IsChecked to false
$sync.$checkboxName.IsChecked = $false
} }
} }
@@ -57,10 +41,9 @@ function Reset-WPFCheckBoxes {
# Only act on toggles that are explicitly listed in the import - toggles absent # Only act on toggles that are explicitly listed in the import - toggles absent
# from the export file were not part of the saved config and should keep whatever # from the export file were not part of the saved config and should keep whatever
# state the live system already has (set during UI initialisation via Get-WinUtilToggleStatus). # state the live system already has (set during UI initialisation via Get-WinUtilToggleStatus).
$importedToggles = $sync.selectedToggles $importedToggles = [System.Collections.Generic.HashSet[string]]::new([string[]]@($sync.selectedToggles), [StringComparer]::OrdinalIgnoreCase)
$allToggles = $sync.GetEnumerator() | Where-Object { $_.Key -like "WPFToggle*" -and $_.Value -is [System.Windows.Controls.CheckBox] } foreach ($toggle in $sync.GetEnumerator()) {
foreach ($toggle in $allToggles) { if ($toggle.Key -like "WPFToggle*" -and $toggle.Value -is [System.Windows.Controls.CheckBox] -and $importedToggles.Contains($toggle.Key)) {
if ($importedToggles -contains $toggle.Key) {
$sync[$toggle.Key].IsChecked = $true $sync[$toggle.Key].IsChecked = $true
} }
# Toggles not present in the import are intentionally left untouched; # Toggles not present in the import are intentionally left untouched;