mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-04-05 22:28:31 +00:00
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:
59
functions/private/Update-WinUtilSelections.ps1
Normal file
59
functions/private/Update-WinUtilSelections.ps1
Normal file
@@ -0,0 +1,59 @@
|
||||
function Update-WinUtilSelections {
|
||||
<#
|
||||
|
||||
.SYNOPSIS
|
||||
Updates the $sync.selected variables with a given preset.
|
||||
|
||||
.PARAMETER flatJson
|
||||
The flattened json list of $sync values to select.
|
||||
#>
|
||||
|
||||
param (
|
||||
$flatJson
|
||||
)
|
||||
|
||||
Write-Debug "JSON to import: $($flatJson)"
|
||||
|
||||
foreach ($cbkey in $flatJson) {
|
||||
$group = if ($cbkey.StartsWith("WPFInstall")) { "Install" }
|
||||
elseif ($cbkey.StartsWith("WPFTweaks")) { "Tweaks" }
|
||||
elseif ($cbkey.StartsWith("WPFToggle")) { "Toggle" }
|
||||
elseif ($cbkey.StartsWith("WPFFeature")) { "Feature" }
|
||||
else { "na" }
|
||||
|
||||
switch ($group) {
|
||||
"Install" {
|
||||
if (!$sync.selectedApps.Contains($cbkey)) {
|
||||
$sync.selectedApps.Add($cbkey)
|
||||
# The List type needs to be specified again, because otherwise Sort-Object will convert the list to a string if there is only a single entry
|
||||
[System.Collections.Generic.List[pscustomobject]]$sync.selectedApps = $sync.SelectedApps | Sort-Object
|
||||
}
|
||||
}
|
||||
"Tweaks" {
|
||||
if (!$sync.selectedTweaks.Contains($cbkey)) {
|
||||
$sync.selectedTweaks.Add($cbkey)
|
||||
}
|
||||
}
|
||||
"Toggle" {
|
||||
if (!$sync.selectedToggles.Contains($cbkey)) {
|
||||
$sync.selectedToggles.Add($cbkey)
|
||||
}
|
||||
}
|
||||
"Feature" {
|
||||
if (!$sync.selectedFeatures.Contains($cbkey)) {
|
||||
$sync.selectedFeatures.Add($cbkey)
|
||||
}
|
||||
}
|
||||
default {
|
||||
Write-Host "Unknown group for checkbox: $($cbkey)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Debug "-------------------------------------"
|
||||
Write-Debug "Selected Apps: $($sync.selectedApps)"
|
||||
Write-Debug "Selected Tweaks: $($sync.selectedTweaks)"
|
||||
Write-Debug "Selected Toggles: $($sync.selectedToggles)"
|
||||
Write-Debug "Selected Features: $($sync.selectedFeatures)"
|
||||
Write-Debug "--------------------------------------"
|
||||
}
|
||||
Reference in New Issue
Block a user