mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Add AppsScriptVariables functionality to UI for defining key-value pairs
- Introduced a new checkbox to enable defining Apps Script Variables. - Added a panel for inputting key-value pairs with validation for duplicates. - Implemented event handlers for adding, removing, and clearing Apps Script Variables. - Updated LoadConfig logic to handle loading of Apps Script Variables from configuration.
This commit is contained in:
@@ -585,7 +585,13 @@ function Get-UIConfig {
|
|||||||
AllowVHDXCaching = $window.FindName('chkAllowVHDXCaching').IsChecked
|
AllowVHDXCaching = $window.FindName('chkAllowVHDXCaching').IsChecked
|
||||||
AppListPath = $window.FindName('txtAppListJsonPath').Text
|
AppListPath = $window.FindName('txtAppListJsonPath').Text
|
||||||
AppsPath = $window.FindName('txtApplicationPath').Text
|
AppsPath = $window.FindName('txtApplicationPath').Text
|
||||||
AppsScriptVariables = $null # Parameter from Sample_default.json, no UI control
|
AppsScriptVariables = if ($window.FindName('chkDefineAppsScriptVariables').IsChecked) {
|
||||||
|
$vars = @{}
|
||||||
|
foreach ($item in $window.FindName('lstAppsScriptVariables').Items) {
|
||||||
|
$vars[$item.Key] = $item.Value
|
||||||
|
}
|
||||||
|
if ($vars.Count -gt 0) { $vars } else { $null }
|
||||||
|
} else { $null }
|
||||||
BuildUSBDrive = $window.FindName('chkBuildUSBDriveEnable').IsChecked
|
BuildUSBDrive = $window.FindName('chkBuildUSBDriveEnable').IsChecked
|
||||||
CleanupAppsISO = $window.FindName('chkCleanupAppsISO').IsChecked
|
CleanupAppsISO = $window.FindName('chkCleanupAppsISO').IsChecked
|
||||||
CleanupCaptureISO = $window.FindName('chkCleanupCaptureISO').IsChecked
|
CleanupCaptureISO = $window.FindName('chkCleanupCaptureISO').IsChecked
|
||||||
@@ -1401,6 +1407,16 @@ $window.Add_Loaded({
|
|||||||
$script:chkCopyDrivers = $window.FindName('chkCopyDrivers')
|
$script:chkCopyDrivers = $window.FindName('chkCopyDrivers')
|
||||||
$script:chkCompressDriversToWIM = $window.FindName('chkCompressDriversToWIM')
|
$script:chkCompressDriversToWIM = $window.FindName('chkCompressDriversToWIM')
|
||||||
|
|
||||||
|
# AppsScriptVariables Controls
|
||||||
|
$script:chkDefineAppsScriptVariables = $window.FindName('chkDefineAppsScriptVariables')
|
||||||
|
$script:appsScriptVariablesPanel = $window.FindName('appsScriptVariablesPanel')
|
||||||
|
$script:txtAppsScriptKey = $window.FindName('txtAppsScriptKey')
|
||||||
|
$script:txtAppsScriptValue = $window.FindName('txtAppsScriptValue')
|
||||||
|
$script:btnAddAppsScriptVariable = $window.FindName('btnAddAppsScriptVariable')
|
||||||
|
$script:lstAppsScriptVariables = $window.FindName('lstAppsScriptVariables')
|
||||||
|
$script:btnRemoveAppsScriptVariable = $window.FindName('btnRemoveAppsScriptVariable')
|
||||||
|
$script:btnClearAppsScriptVariables = $window.FindName('btnClearAppsScriptVariables')
|
||||||
|
|
||||||
# Get Windows Settings defaults and lists from helper module
|
# Get Windows Settings defaults and lists from helper module
|
||||||
$script:windowsSettingsDefaults = Get-WindowsSettingsDefaults
|
$script:windowsSettingsDefaults = Get-WindowsSettingsDefaults
|
||||||
# Get General defaults from helper module
|
# Get General defaults from helper module
|
||||||
@@ -2016,8 +2032,10 @@ $window.Add_Loaded({
|
|||||||
$script:applicationPathPanel.Visibility = 'Visible'
|
$script:applicationPathPanel.Visibility = 'Visible'
|
||||||
$script:appListJsonPathPanel.Visibility = 'Visible'
|
$script:appListJsonPathPanel.Visibility = 'Visible'
|
||||||
$script:chkBringYourOwnApps.Visibility = 'Visible'
|
$script:chkBringYourOwnApps.Visibility = 'Visible'
|
||||||
|
# New logic for AppsScriptVariables
|
||||||
|
$script:chkDefineAppsScriptVariables.Visibility = 'Visible'
|
||||||
})
|
})
|
||||||
$script:chkInstallApps.Add_Unchecked({
|
$script:chkInstallApps.Add_Unchecked({
|
||||||
$script:chkInstallWingetApps.IsChecked = $false # Uncheck children when parent is unchecked
|
$script:chkInstallWingetApps.IsChecked = $false # Uncheck children when parent is unchecked
|
||||||
$script:chkBringYourOwnApps.IsChecked = $false
|
$script:chkBringYourOwnApps.IsChecked = $false
|
||||||
$script:chkInstallWingetApps.Visibility = 'Collapsed'
|
$script:chkInstallWingetApps.Visibility = 'Collapsed'
|
||||||
@@ -2027,6 +2045,10 @@ $window.Add_Loaded({
|
|||||||
$script:wingetPanel.Visibility = 'Collapsed'
|
$script:wingetPanel.Visibility = 'Collapsed'
|
||||||
$script:wingetSearchPanel.Visibility = 'Collapsed'
|
$script:wingetSearchPanel.Visibility = 'Collapsed'
|
||||||
$script:byoApplicationPanel.Visibility = 'Collapsed'
|
$script:byoApplicationPanel.Visibility = 'Collapsed'
|
||||||
|
# New logic for AppsScriptVariables
|
||||||
|
$script:chkDefineAppsScriptVariables.IsChecked = $false # Also uncheck it
|
||||||
|
$script:chkDefineAppsScriptVariables.Visibility = 'Collapsed'
|
||||||
|
$script:appsScriptVariablesPanel.Visibility = 'Collapsed' # Ensure panel is hidden
|
||||||
})
|
})
|
||||||
$script:btnBrowseApplicationPath.Add_Click({
|
$script:btnBrowseApplicationPath.Add_Click({
|
||||||
$selectedPath = Show-ModernFolderPicker -Title "Select Application Path Folder"
|
$selectedPath = Show-ModernFolderPicker -Title "Select Application Path Folder"
|
||||||
@@ -2408,6 +2430,66 @@ $window.Add_Loaded({
|
|||||||
$script:chkCopyDrivers.IsEnabled = $true
|
$script:chkCopyDrivers.IsEnabled = $true
|
||||||
$script:chkCompressDriversToWIM.IsEnabled = $true
|
$script:chkCompressDriversToWIM.IsEnabled = $true
|
||||||
|
|
||||||
|
# AppsScriptVariables Event Handlers
|
||||||
|
$script:chkDefineAppsScriptVariables.Add_Checked({
|
||||||
|
$script:appsScriptVariablesPanel.Visibility = 'Visible'
|
||||||
|
})
|
||||||
|
$script:chkDefineAppsScriptVariables.Add_Unchecked({
|
||||||
|
$script:appsScriptVariablesPanel.Visibility = 'Collapsed'
|
||||||
|
})
|
||||||
|
|
||||||
|
$script:btnAddAppsScriptVariable.Add_Click({
|
||||||
|
$key = $script:txtAppsScriptKey.Text.Trim()
|
||||||
|
$value = $script:txtAppsScriptValue.Text.Trim()
|
||||||
|
|
||||||
|
if ([string]::IsNullOrWhiteSpace($key)) {
|
||||||
|
[System.Windows.MessageBox]::Show("Apps Script Variable Key cannot be empty.", "Input Error", "OK", "Warning")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
# Check for duplicate keys
|
||||||
|
$existingKey = $script:lstAppsScriptVariables.Items | Where-Object { $_.Key -eq $key }
|
||||||
|
if ($existingKey) {
|
||||||
|
[System.Windows.MessageBox]::Show("An Apps Script Variable with the key '$key' already exists.", "Duplicate Key", "OK", "Warning")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$newItem = [PSCustomObject]@{
|
||||||
|
Key = $key
|
||||||
|
Value = $value
|
||||||
|
}
|
||||||
|
$script:lstAppsScriptVariables.Items.Add($newItem)
|
||||||
|
$script:txtAppsScriptKey.Clear()
|
||||||
|
$script:txtAppsScriptValue.Clear()
|
||||||
|
})
|
||||||
|
|
||||||
|
$script:btnRemoveAppsScriptVariable.Add_Click({
|
||||||
|
if ($script:lstAppsScriptVariables.SelectedItem) {
|
||||||
|
$script:lstAppsScriptVariables.Items.Remove($script:lstAppsScriptVariables.SelectedItem)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[System.Windows.MessageBox]::Show("Please select an Apps Script Variable to remove.", "Selection Error", "OK", "Warning")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$script:btnClearAppsScriptVariables.Add_Click({
|
||||||
|
$script:lstAppsScriptVariables.Items.Clear()
|
||||||
|
})
|
||||||
|
|
||||||
|
# Initial state for chkDefineAppsScriptVariables based on chkInstallApps
|
||||||
|
if ($script:chkInstallApps.IsChecked) {
|
||||||
|
$script:chkDefineAppsScriptVariables.Visibility = 'Visible'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$script:chkDefineAppsScriptVariables.Visibility = 'Collapsed'
|
||||||
|
}
|
||||||
|
# Initial state for appsScriptVariablesPanel based on chkDefineAppsScriptVariables
|
||||||
|
if ($script:chkDefineAppsScriptVariables.IsChecked) {
|
||||||
|
$script:appsScriptVariablesPanel.Visibility = 'Visible'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$script:appsScriptVariablesPanel.Visibility = 'Collapsed'
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
# Function to search for Winget apps
|
# Function to search for Winget apps
|
||||||
@@ -2805,6 +2887,62 @@ $btnLoadConfig.Add_Click({
|
|||||||
Set-UIValue -ControlName 'txtApplicationPath' -PropertyName 'Text' -ConfigObject $configContent -ConfigKey 'AppsPath' -WindowInstance $window
|
Set-UIValue -ControlName 'txtApplicationPath' -PropertyName 'Text' -ConfigObject $configContent -ConfigKey 'AppsPath' -WindowInstance $window
|
||||||
Set-UIValue -ControlName 'txtAppListJsonPath' -PropertyName 'Text' -ConfigObject $configContent -ConfigKey 'AppListPath' -WindowInstance $window
|
Set-UIValue -ControlName 'txtAppListJsonPath' -PropertyName 'Text' -ConfigObject $configContent -ConfigKey 'AppListPath' -WindowInstance $window
|
||||||
|
|
||||||
|
# Handle AppsScriptVariables
|
||||||
|
$appsScriptVarsKeyExists = $false
|
||||||
|
if ($configContent -is [System.Management.Automation.PSCustomObject] -and $null -ne $configContent.PSObject.Properties) {
|
||||||
|
try {
|
||||||
|
if (($configContent.PSObject.Properties.Match('AppsScriptVariables')).Count -gt 0) {
|
||||||
|
$appsScriptVarsKeyExists = $true
|
||||||
|
}
|
||||||
|
} catch { WriteLog "ERROR: Exception while trying to Match key 'AppsScriptVariables'. Error: $($_.Exception.Message)" }
|
||||||
|
}
|
||||||
|
|
||||||
|
$lstAppsScriptVars = $window.FindName('lstAppsScriptVariables')
|
||||||
|
$chkDefineAppsScriptVars = $window.FindName('chkDefineAppsScriptVariables')
|
||||||
|
$appsScriptVarsPanel = $window.FindName('appsScriptVariablesPanel')
|
||||||
|
$lstAppsScriptVars.Items.Clear()
|
||||||
|
|
||||||
|
if ($appsScriptVarsKeyExists -and $null -ne $configContent.AppsScriptVariables -and $configContent.AppsScriptVariables -is [System.Management.Automation.PSCustomObject]) {
|
||||||
|
WriteLog "LoadConfig: Processing AppsScriptVariables from config."
|
||||||
|
$loadedVars = $configContent.AppsScriptVariables
|
||||||
|
$hasVars = $false
|
||||||
|
foreach ($prop in $loadedVars.PSObject.Properties) {
|
||||||
|
$lstAppsScriptVars.Items.Add([PSCustomObject]@{ Key = $prop.Name; Value = $prop.Value })
|
||||||
|
$hasVars = $true
|
||||||
|
}
|
||||||
|
if ($hasVars) {
|
||||||
|
$chkDefineAppsScriptVars.IsChecked = $true
|
||||||
|
$appsScriptVarsPanel.Visibility = 'Visible'
|
||||||
|
WriteLog "LoadConfig: Loaded AppsScriptVariables and checked 'Define Apps Script Variables'."
|
||||||
|
} else {
|
||||||
|
$chkDefineAppsScriptVars.IsChecked = $false
|
||||||
|
$appsScriptVarsPanel.Visibility = 'Collapsed'
|
||||||
|
WriteLog "LoadConfig: AppsScriptVariables key was present but empty. Unchecked 'Define Apps Script Variables'."
|
||||||
|
}
|
||||||
|
} elseif ($appsScriptVarsKeyExists -and $null -ne $configContent.AppsScriptVariables -and $configContent.AppsScriptVariables -is [hashtable]) {
|
||||||
|
# Handle if it's already a hashtable (e.g., from older config or direct creation)
|
||||||
|
WriteLog "LoadConfig: Processing AppsScriptVariables (Hashtable) from config."
|
||||||
|
$loadedVars = $configContent.AppsScriptVariables
|
||||||
|
$hasVars = $false
|
||||||
|
foreach ($keyName in $loadedVars.Keys) {
|
||||||
|
$lstAppsScriptVars.Items.Add([PSCustomObject]@{ Key = $keyName; Value = $loadedVars[$keyName] })
|
||||||
|
$hasVars = $true
|
||||||
|
}
|
||||||
|
if ($hasVars) {
|
||||||
|
$chkDefineAppsScriptVars.IsChecked = $true
|
||||||
|
$appsScriptVarsPanel.Visibility = 'Visible'
|
||||||
|
WriteLog "LoadConfig: Loaded AppsScriptVariables (Hashtable) and checked 'Define Apps Script Variables'."
|
||||||
|
} else {
|
||||||
|
$chkDefineAppsScriptVars.IsChecked = $false
|
||||||
|
$appsScriptVarsPanel.Visibility = 'Collapsed'
|
||||||
|
WriteLog "LoadConfig: AppsScriptVariables (Hashtable) key was present but empty. Unchecked 'Define Apps Script Variables'."
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$chkDefineAppsScriptVars.IsChecked = $false
|
||||||
|
$appsScriptVarsPanel.Visibility = 'Collapsed'
|
||||||
|
WriteLog "LoadConfig Info: Key 'AppsScriptVariables' not found, is null, or not a PSCustomObject/Hashtable. Unchecked 'Define Apps Script Variables'."
|
||||||
|
}
|
||||||
|
|
||||||
# Update USB Drive selection if present in config
|
# Update USB Drive selection if present in config
|
||||||
$usbDriveListKeyExists = $false
|
$usbDriveListKeyExists = $false
|
||||||
if ($configContent -is [System.Management.Automation.PSCustomObject] -and $null -ne $configContent.PSObject.Properties) {
|
if ($configContent -is [System.Management.Automation.PSCustomObject] -and $null -ne $configContent.PSObject.Properties) {
|
||||||
|
|||||||
@@ -581,6 +581,47 @@
|
|||||||
<Button x:Name="btnClearBYOApplications" Content="Clear List" Padding="10,5" ToolTip="Clear all applications from the list"/>
|
<Button x:Name="btnClearBYOApplications" Content="Clear List" Padding="10,5" ToolTip="Clear all applications from the list"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- AppsScriptVariables Section -->
|
||||||
|
<CheckBox x:Name="chkDefineAppsScriptVariables" Content="Define Apps Script Variables" Margin="5" ToolTip="Enable to define key-value pairs for Apps Script Variables"/>
|
||||||
|
<StackPanel x:Name="appsScriptVariablesPanel" Visibility="Collapsed" Margin="25,0,5,20">
|
||||||
|
<TextBlock Text="Apps Script Variables" FontWeight="Bold" Margin="0,5,0,10"/>
|
||||||
|
<!-- Input Grid -->
|
||||||
|
<Grid Margin="0,0,0,10">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<TextBlock Text="Key:" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||||
|
<TextBox x:Name="txtAppsScriptKey" Grid.Row="0" Grid.Column="1" Margin="0,0,10,0" ToolTip="Enter the variable key"/>
|
||||||
|
<TextBlock Text="Value:" Grid.Row="0" Grid.Column="2" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||||
|
<TextBox x:Name="txtAppsScriptValue" Grid.Row="0" Grid.Column="3" Margin="0,0,10,0" ToolTip="Enter the variable value"/>
|
||||||
|
<Button x:Name="btnAddAppsScriptVariable" Grid.Row="0" Grid.Column="4" Content="Add Variable" Width="100" ToolTip="Add the key-value pair to the list"/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- ListView for AppsScriptVariables -->
|
||||||
|
<ListView x:Name="lstAppsScriptVariables" Height="150" Margin="0,0,0,10">
|
||||||
|
<ListView.View>
|
||||||
|
<GridView>
|
||||||
|
<GridViewColumn Header="Key" DisplayMemberBinding="{Binding Key}" Width="200"/>
|
||||||
|
<GridViewColumn Header="Value" DisplayMemberBinding="{Binding Value}" Width="300"/>
|
||||||
|
</GridView>
|
||||||
|
</ListView.View>
|
||||||
|
</ListView>
|
||||||
|
|
||||||
|
<!-- Action Buttons for ListView -->
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||||
|
<Button x:Name="btnRemoveAppsScriptVariable" Content="Remove Selected" Margin="0,0,10,0" Padding="10,5" ToolTip="Remove the selected variable from the list"/>
|
||||||
|
<Button x:Name="btnClearAppsScriptVariables" Content="Clear All" Padding="10,5" ToolTip="Clear all variables from the list"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
<!-- End AppsScriptVariables Section -->
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
|
|||||||
Reference in New Issue
Block a user