Decoupled UI and data (#4051)

* Decoupled UI and data

* Fix bad variable naming

* Fix mistype

* Fix mistype v2

Editing from mobile is hard
This commit is contained in:
KamaleiZestri
2026-02-17 12:39:44 -06:00
committed by GitHub
parent 0e41122d89
commit 70a94abe02
14 changed files with 276 additions and 189 deletions

View File

@@ -2,10 +2,10 @@ function Invoke-WPFPresets {
<#
.SYNOPSIS
Sets the options in the tweaks panel to the given preset
Sets the checkboxes in winutil to the given preset
.PARAMETER preset
The preset to set the options to
The preset to set the checkboxes to
.PARAMETER imported
If the preset is imported from a file, defaults to false
@@ -17,7 +17,7 @@ function Invoke-WPFPresets {
param (
[Parameter(position=0)]
[Array]$preset = "",
[Array]$preset = $null,
[Parameter(position=1)]
[bool]$imported = $false,
@@ -32,33 +32,19 @@ function Invoke-WPFPresets {
$CheckBoxesToCheck = $sync.configs.preset.$preset
}
$CheckBoxes = ($sync.GetEnumerator()).where{ $_.Value -is [System.Windows.Controls.CheckBox] -and $_.Name -notlike "WPFToggle*" -and $_.Name -like "$checkboxfilterpattern"}
Write-Debug "Getting checkboxes to set, number of checkboxes: $($CheckBoxes.Count)"
if ($CheckBoxesToCheck -ne "") {
$debugMsg = "CheckBoxes to Check are: "
$CheckBoxesToCheck | ForEach-Object { $debugMsg += "$_, " }
$debugMsg = $debugMsg -replace (',\s*$', '')
Write-Debug "$debugMsg"
}
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
Write-Debug "$checkboxName is checked"
} else {
# If it doesn't exist, set IsChecked to false
$sync.$checkboxName.IsChecked = $false
Write-Debug "$checkboxName is not checked"
# clear out the filtered pattern
if (!$preset) {
switch ($checkboxfilterpattern) {
"WPFTweak*" { $sync.selectedTweaks = [System.Collections.Generic.List[string]]::new() }
"WPFInstall*" { $sync.selectedApps = [System.Collections.Generic.List[string]]::new() }
"WPFeatures" { $sync.selectedFeatures = [System.Collections.Generic.List[string]]::new() }
"WPFToggle" { $sync.selectedToggles = [System.Collections.Generic.List[string]]::new() }
default {}
}
}
else {
Update-WinUtilSelections -flatJson $CheckBoxesToCheck
}
Reset-WPFCheckBoxes -doToggles $false -checkboxfilterpattern $checkboxfilterpattern
}