From 004b42436e80058584b3b73a53c0c9523c35664c Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Wed, 18 Jun 2025 13:24:38 -0700 Subject: [PATCH] Refactor USB drive detection event handler Moves the click event handler for detecting USB drives from the main UI script to the dedicated core handlers module. This change centralizes UI logic, improving code organization and maintainability. --- FFUDevelopment/BuildFFUVM_UI.ps1 | 10 ---------- .../FFUUI.Core/FFUUI.Core.Handlers.psm1 | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/FFUDevelopment/BuildFFUVM_UI.ps1 b/FFUDevelopment/BuildFFUVM_UI.ps1 index cffbb27..b0a5d5a 100644 --- a/FFUDevelopment/BuildFFUVM_UI.ps1 +++ b/FFUDevelopment/BuildFFUVM_UI.ps1 @@ -194,16 +194,6 @@ $window.Add_Loaded({ $script:uiState.Controls.chkLatestCU.IsEnabled = -not $script:uiState.Controls.chkPreviewCU.IsChecked # USB Drive Detection/Selection logic (Keep existing logic) - $script:uiState.Controls.btnCheckUSBDrives.Add_Click({ - $script:uiState.Controls.lstUSBDrives.Items.Clear() - $usbDrives = Get-USBDrives - foreach ($drive in $usbDrives) { - $script:uiState.Controls.lstUSBDrives.Items.Add([PSCustomObject]$drive) - } - if ($script:uiState.Controls.lstUSBDrives.Items.Count -gt 0) { - $script:uiState.Controls.lstUSBDrives.SelectedIndex = 0 - } - }) $script:uiState.Controls.chkSelectAllUSBDrives.Add_Checked({ foreach ($item in $script:uiState.Controls.lstUSBDrives.Items) { $item.IsSelected = $true } $script:uiState.Controls.lstUSBDrives.Items.Refresh() diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 index 611bb57..1c6bebd 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 @@ -2,6 +2,22 @@ function Register-EventHandlers { param([PSCustomObject]$State) WriteLog "Registering UI event handlers..." + # Build Tab Event Handlers + $State.Controls.btnCheckUSBDrives.Add_Click({ + param($eventSource, $routedEventArgs) + $window = [System.Windows.Window]::GetWindow($eventSource) + $localState = $window.Tag + + $localState.Controls.lstUSBDrives.Items.Clear() + $usbDrives = Get-USBDrives + foreach ($drive in $usbDrives) { + $localState.Controls.lstUSBDrives.Items.Add([PSCustomObject]$drive) + } + if ($localState.Controls.lstUSBDrives.Items.Count -gt 0) { + $localState.Controls.lstUSBDrives.SelectedIndex = 0 + } + }) + # Hyper-V tab event handlers $State.Controls.cmbVMSwitchName.Add_SelectionChanged({ param($eventSource, $selectionChangedEventArgs)