Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/content/docs/guides/automation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ To create your own config file:
3. Choose **Export**.
4. Save the exported JSON file.

When editing a configuration manually, hover over an application or tweak in WinUtil to see its configuration key, such as `WPFInstallfirefox` or `WPFTweaksTelemetry`.

Once you have exported a config, launch WinUtil with it using this command:
```powershell
& ([ScriptBlock]::Create((irm "https://christitus.com/win"))) -Config "C:\Path\To\Config.json"
Expand Down
24 changes: 24 additions & 0 deletions functions/private/Get-WinUtilConfigToolTip.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function Get-WinUtilConfigToolTip {
<#
.SYNOPSIS
Builds a tooltip that includes an entry's configuration key.
.PARAMETER Description
The user-facing description of the configuration entry.
.PARAMETER ConfigKey
The key used to reference the entry in an exported configuration.
#>
param(
[AllowEmptyString()]
[string]$Description,

[Parameter(Mandatory)]
[string]$ConfigKey
)

$configKeyText = "Configuration key: $ConfigKey"
if ([string]::IsNullOrWhiteSpace($Description)) {
return $configKeyText
}

return "$Description`n`n$configKeyText"
}
2 changes: 1 addition & 1 deletion functions/private/Initialize-InstallAppEntry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Initialize-InstallAppEntry {
$border = New-Object Windows.Controls.Border
$border.Style = $sync.Form.Resources.AppEntryBorderStyle
$border.Tag = $appKey
$border.ToolTip = $app.description
$border.ToolTip = Get-WinUtilConfigToolTip -Description $app.description -ConfigKey $appKey
$border.Add_MouseLeftButtonUp({
# Resolve through $sync because the border's child is a layout Grid for FOSS entries
$childCheckbox = $sync.$($this.Tag)
Expand Down
13 changes: 10 additions & 3 deletions functions/public/Invoke-WPFUIElements.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ function Invoke-WPFUIElements {
# Iterate through JSON data and organize by panel and category
foreach ($entry in $configHashtable.Keys) {
$entryInfo = $configHashtable[$entry]
$entryToolTip = $entryInfo.description
$isSelectableEntry = [string]::IsNullOrWhiteSpace([string]$entryInfo.type) -or $entryInfo.type -in @("Toggle", "ToggleButton")
$isImportableKey = $entry -match '^(WPFTweaks|WPFToggle|WPFFeature|WPFAppx)'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not advertise toggle keys for headless configs

When a user adds an advertised WPFToggle* key to a configuration and launches the documented -Config workflow, Update-WinUtilSelections stores it only in selectedToggles, but the scripts/main.ps1 config path calls Invoke-WinUtilAutoRun, which processes only tweaks, features, apps, and AppX entries. Because this headless path never creates the form whose Checked handlers apply toggles, the key is silently ignored; exclude WPFToggle here or add toggle handling to the automation path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 8b1c15c. WPFToggle entries are now excluded from advertised configuration keys because Invoke-WinUtilAutoRun does not process selectedToggles in the documented headless -Config path. The tooltip is now limited to checkbox selections that automation actually consumes, and the focused test locks in that exclusion. All 557 tests and Compile.ps1 pass.

if ($isSelectableEntry -and $isImportableKey) {
$entryToolTip = Get-WinUtilConfigToolTip -Description $entryInfo.description -ConfigKey $entry
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

# Create an object for the application
$entryObject = [PSCustomObject]@{
Expand All @@ -81,6 +87,7 @@ function Invoke-WPFUIElements {
Checked = $entryInfo.Checked
ButtonWidth = $entryInfo.ButtonWidth
GroupName = $entryInfo.GroupName # Added for RadioButton groupings
ToolTip = $entryToolTip
}

if (-not $organizedData.ContainsKey($entryObject.Panel)) {
Expand Down Expand Up @@ -190,7 +197,7 @@ function Invoke-WPFUIElements {

$label = New-Object Windows.Controls.Label
$label.Content = $entryInfo.Content
$label.ToolTip = $entryInfo.Description
$label.ToolTip = $entryInfo.ToolTip
$label.HorizontalAlignment = "Left"
$label.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "FontSize")
$label.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor")
Expand Down Expand Up @@ -224,7 +231,7 @@ function Invoke-WPFUIElements {
$toggleButton = New-Object Windows.Controls.Primitives.ToggleButton
$toggleButton.Name = $entryInfo.Name
$toggleButton.Content = $entryInfo.Content[1]
$toggleButton.ToolTip = $entryInfo.Description
$toggleButton.ToolTip = $entryInfo.ToolTip
$toggleButton.HorizontalAlignment = "Left"
$toggleButton.Style = $ToggleButtonStyle
[System.Windows.Automation.AutomationProperties]::SetName($toggleButton, $entryInfo.Content[0])
Expand Down Expand Up @@ -490,7 +497,7 @@ function Invoke-WPFUIElements {
$checkBox.Name = $entryInfo.Name
$checkBox.Content = $entryInfo.Content
$checkBox.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "FontSize")
$checkBox.ToolTip = $entryInfo.Description
$checkBox.ToolTip = $entryInfo.ToolTip
$checkBox.SetResourceReference([Windows.Controls.Control]::MarginProperty, "CheckBoxMargin")
$checkBox.UseLayoutRounding = $true
[System.Windows.Automation.AutomationProperties]::SetName($checkBox, $entryInfo.Content)
Expand Down
50 changes: 50 additions & 0 deletions pester/config-tooltips.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#===========================================================================
# Tests - Configuration tooltips
#===========================================================================

BeforeAll {
$script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
. (Join-Path $script:repoRoot "functions\private\Get-WinUtilConfigToolTip.ps1")
}

Describe "Get-WinUtilConfigToolTip" {
It "appends the configuration key to an existing description" {
$toolTip = Get-WinUtilConfigToolTip `
-Description "Installs Mozilla Firefox." `
-ConfigKey "WPFInstallfirefox"

$toolTip | Should -Be "Installs Mozilla Firefox.`n`nConfiguration key: WPFInstallfirefox"
}

It "shows the configuration key when an entry has no description" {
Get-WinUtilConfigToolTip -Description "" -ConfigKey "WPFOOSUbutton" |
Should -Be "Configuration key: WPFOOSUbutton"
}
}

Describe "Configuration tooltip rendering" {
It "uses configuration-key tooltips for install entries" {
$entryScript = Get-Content -Path (Join-Path $script:repoRoot "functions\private\Initialize-InstallAppEntry.ps1") -Raw

$entryScript | Should -Match '\$border\.ToolTip = Get-WinUtilConfigToolTip -Description \$app\.description -ConfigKey \$appKey'
}

It "uses configuration-key tooltips for generated tweak controls" {
$rendererScript = Get-Content -Path (Join-Path $script:repoRoot "functions\public\Invoke-WPFUIElements.ps1") -Raw

$rendererScript | Should -Match '\$isSelectableEntry = .*"Toggle", "ToggleButton"'
$rendererScript | Should -Match '\$isImportableKey = \$entry -match.*WPFTweaks.*WPFToggle.*WPFFeature.*WPFAppx'
$rendererScript | Should -Match '\$entryToolTip = Get-WinUtilConfigToolTip -Description \$entryInfo\.description -ConfigKey \$entry'
$rendererScript | Should -Match '\$label\.ToolTip = \$entryInfo\.ToolTip'
$rendererScript | Should -Match '\$toggleButton\.ToolTip = \$entryInfo\.ToolTip'
$rendererScript | Should -Match '\$checkBox\.ToolTip = \$entryInfo\.ToolTip'
}

It "keeps non-selectable controls out of configuration-key tooltips" {
$rendererScript = Get-Content -Path (Join-Path $script:repoRoot "functions\public\Invoke-WPFUIElements.ps1") -Raw

$rendererScript | Should -Not -Match '\$button\.ToolTip = \$entryInfo\.ToolTip'
$rendererScript | Should -Match '\$label\.ToolTip = \$entryInfo\.Description'
$rendererScript | Should -Match '\$radioButton\.ToolTip = \$entryInfo\.Description'
}
}