From 8d34e2fa30e31da0eb808689d0374b0b8ea50340 Mon Sep 17 00:00:00 2001 From: Marterich <47688561+Marterich@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:02:36 +0200 Subject: [PATCH] Small fixes to the Get-Installed function and formatting stuff --- functions/public/Invoke-WPFGetInstalled.ps1 | 43 +++++++++---------- .../public/Invoke-WPFSelectedLabelUpdate.ps1 | 2 +- functions/public/Invoke-WPFUIApps.ps1 | 16 ++++--- scripts/main.ps1 | 1 - scripts/start.ps1 | 1 + 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/functions/public/Invoke-WPFGetInstalled.ps1 b/functions/public/Invoke-WPFGetInstalled.ps1 index f90f3aff..53daaab3 100644 --- a/functions/public/Invoke-WPFGetInstalled.ps1 +++ b/functions/public/Invoke-WPFGetInstalled.ps1 @@ -9,46 +9,45 @@ function Invoke-WPFGetInstalled { #> param($checkbox) - - if($sync.ProcessRunning) { + if ($sync.ProcessRunning) { $msg = "[Invoke-WPFGetInstalled] Install process is currently running." [System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning) return } - if(($sync.ChocoRadioButton.IsChecked -eq $false) -and ((Test-WinUtilPackageManager -winget) -eq "not-installed") -and $checkbox -eq "winget") { + if (($sync.ChocoRadioButton.IsChecked -eq $false) -and ((Test-WinUtilPackageManager -winget) -eq "not-installed") -and $checkbox -eq "winget") { return } $preferChoco = $sync.ChocoRadioButton.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) - + $sync.ItemsControl.Dispatcher.Invoke([action] { + $sync.ItemsControl.Items | ForEach-Object { $_.Visibility = [Windows.Visibility]::Collapsed } + $null = $sync.itemsControl.Items.Add($sync.LoadingLabel) + }) + Invoke-WPFRunspace -ParameterList @(("preferChoco", $preferChoco),("checkbox", $checkbox),("ShowOnlyCheckedApps", ${function:Show-OnlyCheckedApps})) -DebugPreference $DebugPreference -ScriptBlock { + param ( + [string]$checkbox, + [boolean]$preferChoco, + [scriptblock]$ShowOnlyCheckedApps + ) $sync.ProcessRunning = $true - $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" }) + $sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "Indeterminate" }) - if($checkbox -eq "winget") { + if ($checkbox -eq "winget") { Write-Host "Getting Installed Programs..." + if ($preferChoco) { $Checkboxes = Invoke-WinUtilCurrentSystem -CheckBox "choco" } + else { $Checkboxes = Invoke-WinUtilCurrentSystem -CheckBox $checkbox } } - if($checkbox -eq "tweaks") { + elseif ($checkbox -eq "tweaks") { Write-Host "Getting Installed Tweaks..." - } - if ($preferChoco -and $checkbox -eq "winget") { - $Checkboxes = Invoke-WinUtilCurrentSystem -CheckBox "choco" - } - else{ $Checkboxes = Invoke-WinUtilCurrentSystem -CheckBox $checkbox } - + $sync.form.Dispatcher.invoke({ - foreach($checkbox in $Checkboxes) { + foreach ($checkbox in $Checkboxes) { $sync.$checkbox.ischecked = $True - } + } }) - $sync.ItemsControl.Dispatcher.Invoke([action]{ + $sync.ItemsControl.Dispatcher.Invoke([action] { $ShowOnlyCheckedApps.Invoke($sync.SelectedApps, $sync.ItemsControl) $sync.ItemsControl.Items.Remove($sync.LoadingLabel) }) diff --git a/functions/public/Invoke-WPFSelectedLabelUpdate.ps1 b/functions/public/Invoke-WPFSelectedLabelUpdate.ps1 index e7c5611e..cdc11b26 100644 --- a/functions/public/Invoke-WPFSelectedLabelUpdate.ps1 +++ b/functions/public/Invoke-WPFSelectedLabelUpdate.ps1 @@ -38,4 +38,4 @@ function Invoke-WPFSelectedLabelUpdate { } else { $SelectedLabel.ToolTip = $Null } -} \ No newline at end of file +} diff --git a/functions/public/Invoke-WPFUIApps.ps1 b/functions/public/Invoke-WPFUIApps.ps1 index 85919f19..d47f8d0f 100644 --- a/functions/public/Invoke-WPFUIApps.ps1 +++ b/functions/public/Invoke-WPFUIApps.ps1 @@ -6,9 +6,9 @@ function Toggle-CategoryVisibility { [System.Windows.Controls.ItemsControl]$ItemsControl ) - $appsInCategory = $ItemsControl.Items | Where-Object { - if ($null -ne $_.Tag){ - $sync.configs.applicationsHashtable.$($_.Tag).Category -eq $Category + $appsInCategory = $ItemsControl.Items | Where-Object { + if ($null -ne $_.Tag) { + $sync.configs.applicationsHashtable.$($_.Tag).Category -eq $Category } } $isCollapsed = $appsInCategory[0].Visibility -eq [Windows.Visibility]::Visible @@ -55,8 +55,12 @@ function Show-OnlyCheckedApps { [Parameter(Mandatory=$true)] [System.Windows.Controls.ItemsControl]$ItemsControl ) - $sync.ShowOnlySelected = -not $sync.ShowOnlySelected - if ($sync.ShowOnlySelected) { + # If no apps are selected, do not allow switching to show only selected + if (($false -eq $sync.ShowOnlySelected) -and ($appKeys.Count -eq 0)) { + return + } + $sync.ShowOnlySelected = -not $sync.ShowOnlySelected + if ($sync.ShowOnlySelected) { $sync.Buttons.ShowSelectedAppsButton.Content = "Show All" foreach ($item in $ItemsControl.Items) { if ($appKeys -contains $item.Tag) { @@ -64,7 +68,7 @@ function Show-OnlyCheckedApps { } else { $item.Visibility = [Windows.Visibility]::Collapsed } - } + } } else { $sync.Buttons.ShowSelectedAppsButton.Content = "Show Selected" $ItemsControl.Items | ForEach-Object { $_.Visibility = [Windows.Visibility]::Visible } diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 0e082358..f7d26b9d 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -124,7 +124,6 @@ $sync.configs.applications.PSObject.Properties | ForEach-Object { Invoke-WPFUIElements -configVariable $sync.configs.appnavigation -targetGridName "appscategory" -columncount 1 Invoke-WPFUIApps -Apps $sync.configs.applicationsHashtable -targetGridName "appspanel" - Invoke-WPFUIElements -configVariable $sync.configs.tweaks -targetGridName "tweakspanel" -columncount 2 Invoke-WPFUIElements -configVariable $sync.configs.feature -targetGridName "featurespanel" -columncount 2 diff --git a/scripts/start.ps1 b/scripts/start.ps1 index fc0e4862..1b6a9a57 100644 --- a/scripts/start.ps1 +++ b/scripts/start.ps1 @@ -42,6 +42,7 @@ $sync.ProcessRunning = $false $sync.selectedApps = [System.Collections.Generic.List[string]]::new() $sync.ShowOnlySeleced = $false $sync.currentTab = "Install" +$sync.ShowOnlySelected = $false if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {