2025-03-01 20:50:12 +01:00
function Initialize-InstallAppEntry {
<#
. SYNOPSIS
Creates the app entry to be placed on the isntall tab for a given app
Used to as part of the Install Tab UI generation
. PARAMETER TargetElement
The Element into which the Apps should be placed
2025-04-02 22:54:44 +02:00
. PARAMETER appKey
2025-03-01 20:50:12 +01:00
The Key of the app inside the $sync . configs . applicationsHashtable
#>
param (
[ Windows.Controls.WrapPanel ] $TargetElement ,
2025-04-02 22:54:44 +02:00
$appKey
2025-03-01 20:50:12 +01:00
)
2025-04-02 22:54:44 +02:00
2025-03-01 20:50:12 +01:00
# Create the outer Border for the application type
$border = New-Object Windows . Controls . Border
2025-04-02 22:54:44 +02:00
$border . Style = $sync . Form . Resources . AppTileBorderStyle
$border . Tag = $appKey
$border . ToolTip = $Apps . $appKey . description
2025-03-01 20:50:12 +01:00
$border . Add_MouseUp ( {
$childCheckbox = ( $this . Child . Children | Where-Object { $_ . Template . TargetType -eq [ System.Windows.Controls.Checkbox ] } ) [ 0 ]
$childCheckBox . isChecked = -not $childCheckbox . IsChecked
} )
$border . Add_MouseEnter ( {
if ( ( $sync . $ ( $this . Tag ) . IsChecked ) -eq $false ) {
$this . SetResourceReference ( [ Windows.Controls.Control ] :: BackgroundProperty , " AppInstallHighlightedColor " )
}
} )
$border . Add_MouseLeave ( {
if ( ( $sync . $ ( $this . Tag ) . IsChecked ) -eq $false ) {
$this . SetResourceReference ( [ Windows.Controls.Control ] :: BackgroundProperty , " AppInstallUnselectedColor " )
}
} )
# Create a DockPanel inside the Border
$dockPanel = New-Object Windows . Controls . DockPanel
$dockPanel . LastChildFill = $true
$border . Child = $dockPanel
# Create the CheckBox, vertically centered
$checkBox = New-Object Windows . Controls . CheckBox
2025-04-02 22:54:44 +02:00
$checkBox . Name = $appKey
$checkbox . Style = $sync . Form . Resources . AppTileCheckboxStyle
2025-03-01 20:50:12 +01:00
$checkbox . Add_Checked ( {
Invoke-WPFSelectedAppsUpdate -type " Add " -checkbox $this
$borderElement = $this . Parent . Parent
$borderElement . SetResourceReference ( [ Windows.Controls.Control ] :: BackgroundProperty , " AppInstallSelectedColor " )
} )
$checkbox . Add_Unchecked ( {
Invoke-WPFSelectedAppsUpdate -type " Remove " -checkbox $this
$borderElement = $this . Parent . Parent
$borderElement . SetResourceReference ( [ Windows.Controls.Control ] :: BackgroundProperty , " AppInstallUnselectedColor " )
} )
2025-04-02 22:54:44 +02:00
2025-03-01 20:50:12 +01:00
# Create a StackPanel for the image and name
$imageAndNamePanel = New-Object Windows . Controls . StackPanel
$imageAndNamePanel . Orientation = " Horizontal "
$imageAndNamePanel . VerticalAlignment = " Center "
# Create the Image and set a placeholder
$image = New-Object Windows . Controls . Image
# $image.Name = "wpfapplogo" + $App.Name
2025-04-02 22:54:44 +02:00
$image . Style = $sync . Form . Resources . AppTileImageStyle
2025-03-01 20:50:12 +01:00
$image . Source = $noimage # Ensure $noimage is defined in your script
$imageAndNamePanel . Children . Add ( $image ) | Out-Null
# Create the TextBlock for the application name
$appName = New-Object Windows . Controls . TextBlock
2025-04-02 22:54:44 +02:00
$appName . Style = $sync . Form . Resources . AppTileNameStyle
$appName . Text = $Apps . $appKey . content
2025-03-01 20:50:12 +01:00
$imageAndNamePanel . Children . Add ( $appName ) | Out-Null
# Add the image and name panel to the Checkbox
$checkBox . Content = $imageAndNamePanel
# Add the checkbox to the DockPanel
[ Windows.Controls.DockPanel ] :: SetDock ( $checkBox , [ Windows.Controls.Dock ] :: Left )
$dockPanel . Children . Add ( $checkBox ) | Out-Null
# Create the StackPanel for the buttons and dock it to the right
$buttonPanel = New-Object Windows . Controls . StackPanel
2025-04-02 22:54:44 +02:00
$buttonPanel . Style = $sync . Form . Resources . AppTileButtonPanelStyle
2025-03-01 20:50:12 +01:00
[ Windows.Controls.DockPanel ] :: SetDock ( $buttonPanel , [ Windows.Controls.Dock ] :: Right )
2025-04-02 22:54:44 +02:00
# Define the button properties
$buttons = @ (
[ PSCustomObject ] @ { Name = " Install " ; Description = " Install or Upgrade the application " ; Tooltip = " Install or Upgrade the application " ; Icon = [ char ] 0xE118 } ,
[ PSCustomObject ] @ { Name = " Uninstall " ; Description = " Uninstall the application " ; Tooltip = " Uninstall the application " ; Icon = [ char ] 0xE74D } ,
[ PSCustomObject ] @ { Name = " Info " ; Description = " Open the application's website in your default browser " ; Tooltip = " Open the application's website in your default browser " ; Icon = [ char ] 0xE946 }
)
2025-03-01 20:50:12 +01:00
2025-04-02 22:54:44 +02:00
# Iterate over each button and create it
foreach ( $button in $buttons ) {
$newButton = New-Object Windows . Controls . Button
$newButton . Style = $sync . Form . Resources . AppTileButtonStyle
$newButton . Content = $button . Icon
$newButton . ToolTip = $button . Tooltip
$buttonPanel . Children . Add ( $newButton ) | Out-Null
switch ( $button . Name ) {
" Install " {
$newButton . Add_Click ( {
$appKey = $this . Parent . Parent . Parent . Tag
$appObject = $sync . configs . applicationsHashtable . $appKey
Invoke-WPFInstall -PackagesToInstall $appObject
} )
}
" Uninstall " {
$newButton . Add_Click ( {
$appKey = $this . Parent . Parent . Parent . Tag
$appObject = $sync . configs . applicationsHashtable . $appKey
Invoke-WPFUnInstall -PackagesToUninstall $appObject
} )
}
" Info " {
$newButton . Add_Click ( {
$appKey = $this . Parent . Parent . Parent . Tag
$appObject = $sync . configs . applicationsHashtable . $appKey
Start-Process $appObject . link
} )
}
}
}
2025-03-01 20:50:12 +01:00
# Add the button panel to the DockPanel
$dockPanel . Children . Add ( $buttonPanel ) | Out-Null
# Add the border to the corresponding Category
$TargetElement . Children . Add ( $border ) | Out-Null
2025-04-02 22:54:44 +02:00
return $checkbox
2025-03-01 20:50:12 +01:00
}