Refactor and centralize UI panel visibility logic

Consolidates the logic for showing and hiding UI elements into dedicated functions, `Update-DriverDownloadPanelVisibility` and `Update-OfficePanelVisibility`.

This change simplifies the event handlers for the "Download Drivers" checkbox by using a single handler for both checked and unchecked states. It also moves the initial UI setup from the main script into the core initialization module, improving code organization and reducing duplication.
This commit is contained in:
rbalsleyMSFT
2025-06-19 16:37:32 -07:00
parent 52085cf521
commit 094e084316
4 changed files with 66 additions and 43 deletions
@@ -239,6 +239,16 @@ function Initialize-UIDefaults {
$State.Controls.chkCopyDrivers.IsChecked = $State.Defaults.generalDefaults.CopyDrivers
$State.Controls.chkCopyPEDrivers.IsChecked = $State.Defaults.generalDefaults.CopyPEDrivers
$State.Controls.chkCompressDriversToWIM.IsChecked = $State.Defaults.generalDefaults.CompressDownloadedDriversToWim
# Drivers tab UI logic
$makeList = @('Microsoft', 'Dell', 'HP', 'Lenovo')
foreach ($m in $makeList) {
[void]$State.Controls.cmbMake.Items.Add($m)
}
if ($State.Controls.cmbMake.Items.Count -gt 0) {
$State.Controls.cmbMake.SelectedIndex = 0
}
Update-DriverDownloadPanelVisibility -State $State
# Set initial state for driver checkbox interplay
Update-DriverCheckboxStates -State $State
@@ -246,6 +256,9 @@ function Initialize-UIDefaults {
# Set initial state for InstallApps checkbox based on updates
Update-InstallAppsState -State $State
# Set initial state for Office panel visibility
Update-OfficePanelVisibility -State $State
}
function Initialize-DynamicUIElements {