Refactors CU checkbox logic to core handlers

Moves the event handling logic for the "Latest CU" and "Preview CU" checkboxes from the main UI script into the core handlers module.

This change centralizes UI event handling, improving code organization and maintainability. The new implementation is also more robust, accessing state via the window's `Tag` property rather than a global script variable.
This commit is contained in:
rbalsleyMSFT
2025-06-18 13:16:34 -07:00
parent fd39b0008e
commit 5e5db62d2a
2 changed files with 26 additions and 12 deletions
-12
View File
@@ -189,18 +189,6 @@ $window.Add_Loaded({
} }
# CU interplay (Keep existing logic) # CU interplay (Keep existing logic)
$script:uiState.Controls.chkLatestCU.Add_Checked({
$script:uiState.Controls.chkPreviewCU.IsEnabled = $false
})
$script:uiState.Controls.chkLatestCU.Add_Unchecked({
$script:uiState.Controls.chkPreviewCU.IsEnabled = $true
})
$script:uiState.Controls.chkPreviewCU.Add_Checked({
$script:uiState.Controls.chkLatestCU.IsEnabled = $false
})
$script:uiState.Controls.chkPreviewCU.Add_Unchecked({
$script:uiState.Controls.chkLatestCU.IsEnabled = $true
})
# Set initial state based on defaults # Set initial state based on defaults
$script:uiState.Controls.chkPreviewCU.IsEnabled = -not $script:uiState.Controls.chkLatestCU.IsChecked $script:uiState.Controls.chkPreviewCU.IsEnabled = -not $script:uiState.Controls.chkLatestCU.IsChecked
$script:uiState.Controls.chkLatestCU.IsEnabled = -not $script:uiState.Controls.chkPreviewCU.IsChecked $script:uiState.Controls.chkLatestCU.IsEnabled = -not $script:uiState.Controls.chkPreviewCU.IsChecked
@@ -82,6 +82,32 @@ function Register-EventHandlers {
$State.Controls.chkInstallOffice.Add_Checked($updateCheckboxHandler) $State.Controls.chkInstallOffice.Add_Checked($updateCheckboxHandler)
$State.Controls.chkInstallOffice.Add_Unchecked($updateCheckboxHandler) $State.Controls.chkInstallOffice.Add_Unchecked($updateCheckboxHandler)
# CU Interplay Event Handlers
$State.Controls.chkLatestCU.Add_Checked({
param($eventSource, $routedEventArgs)
$window = [System.Windows.Window]::GetWindow($eventSource)
$localState = $window.Tag
$localState.Controls.chkPreviewCU.IsEnabled = $false
})
$State.Controls.chkLatestCU.Add_Unchecked({
param($eventSource, $routedEventArgs)
$window = [System.Windows.Window]::GetWindow($eventSource)
$localState = $window.Tag
$localState.Controls.chkPreviewCU.IsEnabled = $true
})
$State.Controls.chkPreviewCU.Add_Checked({
param($eventSource, $routedEventArgs)
$window = [System.Windows.Window]::GetWindow($eventSource)
$localState = $window.Tag
$localState.Controls.chkLatestCU.IsEnabled = $false
})
$State.Controls.chkPreviewCU.Add_Unchecked({
param($eventSource, $routedEventArgs)
$window = [System.Windows.Window]::GetWindow($eventSource)
$localState = $window.Tag
$localState.Controls.chkLatestCU.IsEnabled = $true
})
# M365 Apps/Office tab Event Handlers # M365 Apps/Office tab Event Handlers
$State.Controls.chkInstallOffice.Add_Checked({ $State.Controls.chkInstallOffice.Add_Checked({
param($eventSource, $routedEventArgs) param($eventSource, $routedEventArgs)