Add Get-Installed Loading Indicator + small fixes

This commit is contained in:
Marterich 2024-10-13 20:33:26 +02:00
parent 6d88e51462
commit cf664bd1d3
6 changed files with 21 additions and 47 deletions

View File

@ -20,9 +20,13 @@ function Invoke-WPFGetInstalled {
return
}
$preferChoco = $sync.WPFpreferChocolatey.IsChecked
$sync.ItemsControl.Dispatcher.Invoke([action]{
$sync.ItemsControl.Items | ForEach-Object { $_.Visibility = [Windows.Visibility]::Collapsed}
$null = $sync.itemsControl.Items.Add($sync.LoadingLabel)
})
Invoke-WPFRunspace -ArgumentList $checkbox, $preferChoco -ParameterList @(,("ShowOnlyCheckedApps",${function:Show-OnlyCheckedApps})) -DebugPreference $DebugPreference -ScriptBlock {
param($checkbox, $preferChoco, $ShowOnlyCheckedApps,$DebugPreference)
Write-Host $ShowOnlyCheckedApps.ToString()
$sync.ProcessRunning = $true
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })
@ -46,6 +50,7 @@ function Invoke-WPFGetInstalled {
})
$sync.ItemsControl.Dispatcher.Invoke([action]{
$ShowOnlyCheckedApps.Invoke($sync.SelectedApps, $sync.ItemsControl)
$sync.ItemsControl.Items.Remove($sync.LoadingLabel)
})
Write-Host "Done..."
$sync.ProcessRunning = $false

View File

@ -27,4 +27,5 @@ function Invoke-WPFTab {
$sync.$tabNav.Items[$tabNumber].IsSelected = $true
}
}
$sync.currentTab = $sync.$tabNav.Items[$tabNumber].Header
}

View File

@ -50,12 +50,11 @@ function Search-AppsByNameOrDescription {
}
function Show-OnlyCheckedApps {
param (
[Parameter(Mandatory=$true)]
[Parameter(Mandatory=$false)]
[String[]]$appKeys,
[Parameter(Mandatory=$true)]
[System.Windows.Controls.ItemsControl]$ItemsControl
)
Write-Host "Showing only $($appKeys.Count) apps"
$sync.ShowOnlySelected = -not $sync.ShowOnlySelected
if ($sync.ShowOnlySelected) {
$sync.Buttons.ShowSelectedAppsButton.Content = "Show All"
@ -76,7 +75,6 @@ function Invoke-WPFUIApps {
param(
[Parameter(Mandatory, Position = 0)]
[PSCustomObject[]]$Apps,
[Parameter(Mandatory, Position = 1)]
[string]$TargetGridName,
[Parameter()]
@ -151,9 +149,7 @@ function Invoke-WPFUIApps {
$showSelectedAppsButton.Name = "ShowSelectedAppsButton"
$showSelectedAppsButton.Content = "Show Selected"
$showSelectedAppsButton.Add_Click({
if ($sync.SelectedApps.Count -gt 0) {
Show-OnlyCheckedApps -appKeys $sync.SelectedApps -ItemsControl $sync.ItemsControl
}
})
$sync.Buttons.ShowSelectedAppsButton = $showSelectedAppsButton
$null = $wrapPanelTop.Children.Add($showSelectedAppsButton)
@ -230,12 +226,13 @@ function Invoke-WPFUIApps {
$loadingLabel.Content = "Loading, please wait..."
$loadingLabel.HorizontalAlignment = "Center"
$loadingLabel.VerticalAlignment = "Center"
$loadingLabel.FontSize = 16
$loadingLabel.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "FontSizeHeading")
$loadingLabel.FontWeight = [Windows.FontWeights]::Bold
$loadingLabel.Foreground = [Windows.Media.Brushes]::Gray
$sync.LoadingLabel = $
$itemsControl.Items.Clear()
$null = $itemsControl.Items.Add($loadingLabel)
$null = $itemsControl.Items.Add($sync.LoadingLabel)
$itemsControl.Dispatcher.Invoke([System.Windows.Threading.DispatcherPriority]::Background, [action]{
$itemsControl.Items.Clear()

View File

@ -123,9 +123,7 @@ function Invoke-WPFUIElements {
if ($configVariable -eq $sync.configs.applications) {
# Create a WrapPanel to hold buttons at the top
$wrapPanelTop = New-Object Windows.Controls.WrapPanel
$wrapPanelTop.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "MainBackgroundColor")
$wrapPanelTop.HorizontalAlignment = "Left"
$wrapPanelTop.VerticalAlignment = "Top"
$wrapPanelTop.Orientation = "Horizontal"
@ -210,10 +208,8 @@ function Invoke-WPFUIElements {
$label = New-Object Windows.Controls.Label
$label.Content = $category -replace ".*__", ""
$label.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "FontSizeHeading")
$label.SetResourceReference([Windows.Controls.Control]::FontFamilyProperty, "HeaderFontFamily")
$itemsControl.Items.Add($label) | Out-Null
$sync[$category] = $label
@ -234,13 +230,11 @@ function Invoke-WPFUIElements {
$border.HorizontalAlignment = "Stretch"
$border.VerticalAlignment = "Top"
$border.Margin = New-Object Windows.Thickness(0, 10, 0, 0)
$border.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallUnselectedColor")
$border.Add_MouseUp({
$childCheckbox = ($this.Child.Children | Where-Object {$_.Template.TargetType -eq [System.Windows.Controls.Checkbox]})[0]
$childCheckBox.isChecked = -not $childCheckbox.IsChecked
})
# Create a DockPanel inside the Border
$dockPanel = New-Object Windows.Controls.DockPanel
$dockPanel.LastChildFill = $true
@ -249,7 +243,6 @@ function Invoke-WPFUIElements {
# Create the CheckBox, vertically centered
$checkBox = New-Object Windows.Controls.CheckBox
$checkBox.Name = $entryInfo.Name
$checkBox.Background = "Transparent"
$checkBox.HorizontalAlignment = "Left"
$checkBox.VerticalAlignment = "Center"
@ -265,7 +258,6 @@ function Invoke-WPFUIElements {
$borderElement = $this.Parent.Parent
$borderElement.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallUnselectedColor")
})
# Create a StackPanel for the image and name
$imageAndNamePanel = New-Object Windows.Controls.StackPanel
$imageAndNamePanel.Orientation = "Horizontal"
@ -294,7 +286,6 @@ function Invoke-WPFUIElements {
$appName.FontWeight = [Windows.FontWeights]::Bold
$appName.VerticalAlignment = "Center"
$appName.Margin = New-Object Windows.Thickness(5, 0, 0, 0)
$appName.Background = "Transparent"
$imageAndNamePanel.Children.Add($appName) | Out-Null
@ -323,9 +314,7 @@ function Invoke-WPFUIElements {
$installIcon.Text = [char]0xE118 # Install Icon
$installIcon.FontFamily = "Segoe MDL2 Assets"
$installIcon.FontSize = 20
$installIcon.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor")
$installIcon.Background = "Transparent"
$installIcon.HorizontalAlignment = "Center"
$installIcon.VerticalAlignment = "Center"
@ -347,9 +336,7 @@ function Invoke-WPFUIElements {
$uninstallIcon.Text = [char]0xE74D # Uninstall Icon
$uninstallIcon.FontFamily = "Segoe MDL2 Assets"
$uninstallIcon.FontSize = 20
$uninstallIcon.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor")
$uninstallIcon.Background = "Transparent"
$uninstallIcon.HorizontalAlignment = "Center"
$uninstallIcon.VerticalAlignment = "Center"
@ -371,9 +358,7 @@ function Invoke-WPFUIElements {
$infoIcon.Text = [char]0xE946 # Info Icon
$infoIcon.FontFamily = "Segoe MDL2 Assets"
$infoIcon.FontSize = 20
$infoIcon.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor")
$infoIcon.Background = "Transparent"
$infoIcon.HorizontalAlignment = "Center"
$infoIcon.VerticalAlignment = "Center"
@ -431,9 +416,7 @@ function Invoke-WPFUIElements {
$label.Content = $entryInfo.Content
$label.ToolTip = $entryInfo.Description
$label.HorizontalAlignment = "Left"
$label.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "FontSize")
$label.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor")
$dockPanel.Children.Add($label) | Out-Null
$itemsControl.Items.Add($dockPanel) | Out-Null
@ -452,18 +435,14 @@ function Invoke-WPFUIElements {
$toggleButton = New-Object Windows.Controls.ToggleButton
$toggleButton.Name = $entryInfo.Name
$toggleButton.HorizontalAlignment = "Left"
$toggleButton.SetResourceReference([Windows.Controls.Control]::HeightProperty, "TabButtonHeight")
$toggleButton.SetResourceReference([Windows.Controls.Control]::WidthProperty, "TabButtonWidth")
$toggleButton.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "ButtonInstallBackgroundColor")
$toggleButton.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor")
$toggleButton.FontWeight = [Windows.FontWeights]::Bold
$textBlock = New-Object Windows.Controls.TextBlock
$textBlock.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "TabButtonFontSize")
$textBlock.Background = [Windows.Media.Brushes]::Transparent
$textBlock.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "ButtonInstallForegroundColor")
@ -492,14 +471,11 @@ function Invoke-WPFUIElements {
$label.Content = $entryInfo.Content
$label.HorizontalAlignment = "Left"
$label.VerticalAlignment = "Center"
$label.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "ButtonFontSize")
$horizontalStackPanel.Children.Add($label) | Out-Null
$comboBox = New-Object Windows.Controls.ComboBox
$comboBox.Name = $entryInfo.Name
$comboBox.SetResourceReference([Windows.Controls.Control]::HeightProperty, "ButtonHeight")
$comboBox.SetResourceReference([Windows.Controls.Control]::WidthProperty, "ButtonWidth")
$comboBox.HorizontalAlignment = "Left"
@ -509,9 +485,7 @@ function Invoke-WPFUIElements {
foreach ($comboitem in ($entryInfo.ComboItems -split " ")) {
$comboBoxItem = New-Object Windows.Controls.ComboBoxItem
$comboBoxItem.Content = $comboitem
$comboBoxItem.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "ButtonFontSize")
$comboBox.Items.Add($comboBoxItem) | Out-Null
}
@ -528,10 +502,8 @@ function Invoke-WPFUIElements {
$button.Name = $entryInfo.Name
$button.Content = $entryInfo.Content
$button.HorizontalAlignment = "Left"
$button.SetResourceReference([Windows.Controls.Control]::MarginProperty, "ButtonMargin")
$button.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "ButtonFontSize")
if ($entryInfo.ButtonWidth) {
$button.Width = $entryInfo.ButtonWidth
}
@ -560,10 +532,8 @@ function Invoke-WPFUIElements {
$radioButton.GroupName = $entryInfo.GroupName
$radioButton.Content = $entryInfo.Content
$radioButton.HorizontalAlignment = "Left"
$radioButton.SetResourceReference([Windows.Controls.Control]::MarginProperty, "CheckBoxMargin")
$radioButton.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "ButtonFontSize")
$radioButton.ToolTip = $entryInfo.Description
if ($entryInfo.Checked -eq $true) {
@ -582,11 +552,9 @@ function Invoke-WPFUIElements {
$checkBox = New-Object Windows.Controls.CheckBox
$checkBox.Name = $entryInfo.Name
$checkBox.Content = $entryInfo.Content
$checkBox.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "FontSize")
$checkBox.ToolTip = $entryInfo.Description
$checkBox.SetResourceReference([Windows.Controls.Control]::MarginProperty, "CheckBoxMargin")
if ($entryInfo.Checked -eq $true) {
$checkBox.IsChecked = $entryInfo.Checked
}

View File

@ -114,7 +114,6 @@ Invoke-WinutilThemeChange -init $true
$noimage = "https://images.emojiterra.com/google/noto-emoji/unicode-15/color/512px/1f4e6.png"
$noimage = [Windows.Media.Imaging.BitmapImage]::new([Uri]::new($noimage))
$sync.Buttons = @{}
$SortedAppsHashtable = [ordered]@{}
$sortedProperties = $sync.configs.applications.PSObject.Properties | Sort-Object { $_.Value.Content }
@ -124,9 +123,9 @@ $sortedProperties | ForEach-Object {
# Now call the function with the final merged config
Invoke-WPFUIElements -configVariable $sync.configs.appnavigation -targetGridName "appscategory" -columncount 1
Invoke-WPFUIApps -Apps $SortedAppsHashtable -targetGridName "appspanel"
Invoke-WPFUIElements -configVariable $sync.configs.tweaks -targetGridName "tweakspanel" -columncount 2
Invoke-WPFUIElements -configVariable $sync.configs.feature -targetGridName "featurespanel" -columncount 2
@ -458,7 +457,11 @@ $sync["SearchBar"].Add_TextChanged({
} else {
$sync.SearchBarClearButton.Visibility = "Collapsed"
}
switch ($sync.currentTab) {
"Install" {
Search-AppsByNameOrDescription -SearchString $sync.SearchBar.Text
}
}
})
$sync["Form"].Add_Loaded({
@ -590,9 +593,6 @@ $sync["SponsorMenuItem"].Add_Click({
Show-CustomDialog -Message $authorInfo -EnableScroll $true
})
#Initialize List to store the Names of the selected Apps on the Install Tab
$sync.selectedApps = [System.Collections.Generic.List[string]]::new()
$sync.ShowOnlySeleced = $false
$sync["Form"].ShowDialog() | out-null

View File

@ -38,6 +38,9 @@ $sync.PSScriptRoot = $PSScriptRoot
$sync.version = "#{replaceme}"
$sync.configs = @{}
$sync.ProcessRunning = $false
$sync.selectedApps = [System.Collections.Generic.List[string]]::new()
$sync.ShowOnlySeleced = $false
$sync.currentTab = "Install"
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Output "Winutil needs to be run as Administrator. Attempting to relaunch."