mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Refactor: Centralize Install Apps checkbox logic
Consolidates the state management for the "Install Apps" checkbox into a single, reusable function. Previously, the logic to automatically check and disable "Install Apps" when selecting an update or installing Office was duplicated and scattered across multiple event handlers and files. This change introduces a new core function that centralizes this behavior. A single event handler is now used for all relevant checkboxes (Updates and Office), simplifying the UI code, reducing redundancy, and making the logic more robust and maintainable. The initial state is also set correctly on startup.
This commit is contained in:
@@ -188,6 +188,43 @@ function Get-USBDrives {
|
||||
}
|
||||
}
|
||||
|
||||
# Function to manage the state of the main "Install Apps" checkbox based on selections in Updates/Office
|
||||
function Update-InstallAppsState {
|
||||
param([PSCustomObject]$State)
|
||||
|
||||
$installAppsChk = $State.Controls.chkInstallApps
|
||||
$installOfficeChk = $State.Controls.chkInstallOffice
|
||||
|
||||
# Determine if any checkbox that forces "Install Apps" is checked
|
||||
$anyUpdateChecked = $State.Controls.chkUpdateLatestDefender.IsChecked -or `
|
||||
$State.Controls.chkUpdateEdge.IsChecked -or `
|
||||
$State.Controls.chkUpdateOneDrive.IsChecked -or `
|
||||
$State.Controls.chkUpdateLatestMSRT.IsChecked
|
||||
|
||||
$isForced = $anyUpdateChecked -or $installOfficeChk.IsChecked
|
||||
|
||||
if ($isForced) {
|
||||
# If InstallApps is not already forced (i.e., it's enabled), save its current state.
|
||||
if ($installAppsChk.IsEnabled) {
|
||||
$State.Flags.prevInstallAppsState = $installAppsChk.IsChecked
|
||||
}
|
||||
$installAppsChk.IsChecked = $true
|
||||
$installAppsChk.IsEnabled = $false
|
||||
}
|
||||
else {
|
||||
# No longer forced. Restore the previous state if it was saved.
|
||||
if ($State.Flags.ContainsKey('prevInstallAppsState')) {
|
||||
$installAppsChk.IsChecked = $State.Flags.prevInstallAppsState
|
||||
$State.Flags.Remove('prevInstallAppsState') # Use the saved state only once
|
||||
}
|
||||
else {
|
||||
# If no state was saved (e.g., it was never forced), ensure it's unchecked.
|
||||
$installAppsChk.IsChecked = $false
|
||||
}
|
||||
$installAppsChk.IsEnabled = $true
|
||||
}
|
||||
}
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# SECTION: Module Export
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user