From 5e5db62d2a9902e135ff496b9f5afc16e16cd90d Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Wed, 18 Jun 2025 13:16:34 -0700 Subject: [PATCH] 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. --- FFUDevelopment/BuildFFUVM_UI.ps1 | 12 --------- .../FFUUI.Core/FFUUI.Core.Handlers.psm1 | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/FFUDevelopment/BuildFFUVM_UI.ps1 b/FFUDevelopment/BuildFFUVM_UI.ps1 index 49afac7..cffbb27 100644 --- a/FFUDevelopment/BuildFFUVM_UI.ps1 +++ b/FFUDevelopment/BuildFFUVM_UI.ps1 @@ -189,18 +189,6 @@ $window.Add_Loaded({ } # 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 $script:uiState.Controls.chkPreviewCU.IsEnabled = -not $script:uiState.Controls.chkLatestCU.IsChecked $script:uiState.Controls.chkLatestCU.IsEnabled = -not $script:uiState.Controls.chkPreviewCU.IsChecked diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 index 1d2d21c..611bb57 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 @@ -82,6 +82,32 @@ function Register-EventHandlers { $State.Controls.chkInstallOffice.Add_Checked($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 $State.Controls.chkInstallOffice.Add_Checked({ param($eventSource, $routedEventArgs)