Files
winutil/functions/private/Get-WinUtilTweaksStateReport.ps1
T
eduardodepaivaandChris Titus 40666e1d31 style(ui): replace 'Get' with 'Select' (#5054)
* style(ui): replace 'Get' with 'Select'

To a programmer, 'Get' means read the current state. To a lay user, 'Get' means obtain or download (like the 'Get' button in the Microsoft Store).
'Select' indicates exactly what it does and maintains parallelism with 'Select All'.

* docs: align installed tweak references with selection labels

---------

Co-authored-by: Chris Titus <contact@christitus.com>
2026-09-29 11:20:07 -05:00

63 lines
2.6 KiB
PowerShell

function Get-WinUtilTweaksStateReport {
<#
.SYNOPSIS
Groups every config/tweaks.json entry's live applied state by category, reusing the same
detection Invoke-WPFGetInstalled uses to check the "Select Installed Tweaks" checkboxes.
#>
$categoryFieldNames = [ordered]@{
"Essential Tweaks" = "essentialTweaks"
"Customize Preferences" = "customizePreferences"
"z__Advanced Tweaks - CAUTION" = "advancedTweaks"
"Performance Plans - NOT FOR LAPTOPS" = "performancePlans"
}
$grouped = [ordered]@{}
foreach ($fieldName in $categoryFieldNames.Values) {
$grouped[$fieldName] = [ordered]@{}
}
$notEvaluable = [System.Collections.Generic.List[string]]::new()
$collectionStatus = "collected"
try {
$appliedTweaks = [System.Collections.Generic.HashSet[string]]::new(
[string[]]@(Invoke-WinUtilCurrentSystem -CheckBox "tweaks" `
-BypassToggleStatusCache -StopOnReadError)
)
foreach ($property in $sync.configs.tweaks.PSObject.Properties) {
$tweakKey = $property.Name
$entry = $property.Value
$fieldName = $categoryFieldNames[[string]$entry.category]
# Buttons embedded in the tweaks panel (e.g. the OOSU/Ultimate Performance launchers)
# are actions, not stateful tweaks, so they're outside this report's scope entirely.
if (-not $fieldName -or $entry.Type -eq "Button") {
continue
}
# Combobox tweaks and script-only tweaks with no registry/service schema have no
# detectable current state. List them so the report doesn't silently drop them.
if ($entry.Type -eq "Combobox" -or (-not $entry.registry -and -not $entry.service)) {
$notEvaluable.Add($tweakKey)
continue
}
$grouped[$fieldName][$tweakKey] = $appliedTweaks.Contains($tweakKey)
}
} catch {
Write-WinUtilLog -Component "EnvironmentReport" -Level "WARN" -Message "Failed to collect tweaks/toggle state: $($_.Exception.Message)"
$collectionStatus = "unavailable"
}
# Empty groups from a failed collection would otherwise be indistinguishable in the JSON from a
# successful scan that found nothing notable, so record whether collection actually ran.
$result = [ordered]@{ collectionStatus = $collectionStatus }
foreach ($fieldName in $categoryFieldNames.Values) {
$result[$fieldName] = [pscustomobject]$grouped[$fieldName]
}
$result.notEvaluable = @($notEvaluable)
return [pscustomobject]$result
}