From dcf752fdeb282db438efe5b0a8a5275b95e4f5d2 Mon Sep 17 00:00:00 2001 From: Marterich <47688561+Marterich@users.noreply.github.com> Date: Mon, 14 Oct 2024 19:17:12 +0200 Subject: [PATCH] Remove Alphabetical List, Sort Apps inside Category Alphabetically --- config/appnavigation.json | 18 ---------- functions/public/Invoke-WPFInstall.ps1 | 2 +- .../public/Invoke-WPFSelectedLabelUpdate.ps1 | 2 +- functions/public/Invoke-WPFUIApps.ps1 | 35 +++++++------------ functions/public/Invoke-WPFUnInstall.ps1 | 2 +- scripts/main.ps1 | 24 +++---------- scripts/start.ps1 | 2 ++ 7 files changed, 23 insertions(+), 62 deletions(-) diff --git a/config/appnavigation.json b/config/appnavigation.json index 0fb45a1035..dd2f17ac6f 100644 --- a/config/appnavigation.json +++ b/config/appnavigation.json @@ -13,24 +13,6 @@ "Order": "2", "Description": "Clear the selection of applications" }, - "SortbyCategory": { - "Content": "Category", - "Category": "___Sort by", - "Type": "RadioButton", - "GroupName": "SortAppsByGroup", - "Checked": true, - "Order": "1", - "Description": "" - }, - "SortbyAlphabet": { - "Content": "Alphabetical Order", - "Category": "___Sort by", - "Type": "RadioButton", - "GroupName": "SortAppsByGroup", - "Checked": false, - "Order": "2", - "Description": "" - }, "WingetRadioButton": { "Content": "Winget", "Category": "__Package Manager", diff --git a/functions/public/Invoke-WPFInstall.ps1 b/functions/public/Invoke-WPFInstall.ps1 index f51bb5900a..97069662f6 100644 --- a/functions/public/Invoke-WPFInstall.ps1 +++ b/functions/public/Invoke-WPFInstall.ps1 @@ -1,7 +1,7 @@ function Invoke-WPFInstall { param ( [Parameter(Mandatory=$false)] - [PSObject[]]$PackagesToInstall = $($sync.selectedApps | Foreach-Object { $SortedAppsHashtable.$_ }) + [PSObject[]]$PackagesToInstall = $($sync.selectedApps | Foreach-Object { $sync.configs.applicationsHashtable.$_ }) ) <# diff --git a/functions/public/Invoke-WPFSelectedLabelUpdate.ps1 b/functions/public/Invoke-WPFSelectedLabelUpdate.ps1 index a955b6738d..e7c5611ed0 100644 --- a/functions/public/Invoke-WPFSelectedLabelUpdate.ps1 +++ b/functions/public/Invoke-WPFSelectedLabelUpdate.ps1 @@ -34,7 +34,7 @@ function Invoke-WPFSelectedLabelUpdate { $count = $sync.SelectedApps.Count $SelectedLabel.Content = "Selected Apps: $count" if ($count -gt 0) { - $SelectedLabel.ToolTip = $($sync.SelectedApps | Foreach-Object { $SortedAppsHashtable.$_.Content }) -join "`n" + $SelectedLabel.ToolTip = $($sync.SelectedApps | Foreach-Object { $sync.configs.applicationsHashtable.$_.Content }) -join "`n" } else { $SelectedLabel.ToolTip = $Null } diff --git a/functions/public/Invoke-WPFUIApps.ps1 b/functions/public/Invoke-WPFUIApps.ps1 index f1fcc7a0d0..85919f19af 100644 --- a/functions/public/Invoke-WPFUIApps.ps1 +++ b/functions/public/Invoke-WPFUIApps.ps1 @@ -8,7 +8,7 @@ function Toggle-CategoryVisibility { $appsInCategory = $ItemsControl.Items | Where-Object { if ($null -ne $_.Tag){ - $SortedAppsHashtable.$($_.Tag).Category -eq $Category + $sync.configs.applicationsHashtable.$($_.Tag).Category -eq $Category } } $isCollapsed = $appsInCategory[0].Visibility -eq [Windows.Visibility]::Visible @@ -39,7 +39,7 @@ function Search-AppsByNameOrDescription { } else { $Apps | ForEach-Object { if ($null -ne $_.Tag) { - if ($SortedAppsHashtable.$($_.Tag).Content -like "*$SearchString*") { + if ($sync.configs.applicationsHashtable.$($_.Tag).Content -like "*$SearchString*") { $_.Visibility = 'Visible' } else { $_.Visibility = 'Collapsed' @@ -76,9 +76,7 @@ function Invoke-WPFUIApps { [Parameter(Mandatory, Position = 0)] [PSCustomObject[]]$Apps, [Parameter(Mandatory, Position = 1)] - [string]$TargetGridName, - [Parameter()] - [System.Boolean]$Alphabetical = $false + [string]$TargetGridName ) function Initialize-StackPanel { @@ -219,8 +217,7 @@ function Invoke-WPFUIApps { function New-CategoryAppList { param( $TargetGrid, - $Apps, - [System.Boolean]$Alphabetical + $Apps ) $loadingLabel = New-Object Windows.Controls.Label $loadingLabel.Content = "Loading, please wait..." @@ -237,17 +234,11 @@ function Invoke-WPFUIApps { $itemsControl.Dispatcher.Invoke([System.Windows.Threading.DispatcherPriority]::Background, [action]{ $itemsControl.Items.Clear() - if (-not ($Alphabetical)) { - $categories = $Apps.Values | Select-Object -ExpandProperty category -Unique | Sort-Object - foreach ($category in $categories) { - Add-CategoryLabel -Category $category -ItemsControl $itemsControl - $Apps.Keys | Where-Object { $Apps.$_.Category -eq $category } | ForEach-Object { - New-AppEntry -ItemsControl $itemsControl -AppKey $_ -Hidden $true - } - } - } else { - foreach ($appKey in $Apps.Keys) { - New-AppEntry -ItemsControl $itemsControl -AppKey $appKey -Hidden $false + $categories = $Apps.Values | Select-Object -ExpandProperty category -Unique | Sort-Object + foreach ($category in $categories) { + Add-CategoryLabel -Category $category -ItemsControl $itemsControl + $Apps.Keys | Where-Object { $Apps.$_.Category -eq $category } | Sort-Object | ForEach-Object { + New-AppEntry -ItemsControl $itemsControl -AppKey $_ -Hidden $true } } }) @@ -369,7 +360,7 @@ function Invoke-WPFUIApps { # Add Click event for the "Install" button $installButton.Add_Click({ $appKey = $this.Parent.Parent.Parent.Tag - $appObject = $SortedAppsHashtable.$appKey + $appObject = $sync.configs.applicationsHashtable.$appKey Invoke-WPFInstall -PackagesToInstall $appObject }) @@ -393,7 +384,7 @@ function Invoke-WPFUIApps { $uninstallButton.ToolTip = "Uninstall the application" $uninstallButton.Add_Click({ $appKey = $this.Parent.Parent.Parent.Tag - $appObject = $SortedAppsHashtable.$appKey + $appObject = $sync.configs.applicationsHashtable.$appKey Invoke-WPFUnInstall -PackagesToUninstall $appObject }) @@ -418,7 +409,7 @@ function Invoke-WPFUIApps { $infoButton.Add_Click({ $appKey = $this.Parent.Parent.Parent.Tag - $appObject = $SortedAppsHashtable.$appKey + $appObject = $sync.configs.applicationsHashtable.$appKey Start-Process $appObject.link }) @@ -438,7 +429,7 @@ function Invoke-WPFUIApps { $dockPanelContainer = Initialize-Header -TargetGrid $targetGrid $itemsControl = Initialize-AppArea -TargetGrid $dockPanelContainer $sync.ItemsControl = $itemsControl - New-CategoryAppList -TargetGrid $itemsControl -Apps $Apps -Alphabetical $Alphabetical + New-CategoryAppList -TargetGrid $itemsControl -Apps $Apps } default { Write-Output "$TargetGridName not yet implemented" diff --git a/functions/public/Invoke-WPFUnInstall.ps1 b/functions/public/Invoke-WPFUnInstall.ps1 index 45bf1b21be..d3d4cfb4d8 100644 --- a/functions/public/Invoke-WPFUnInstall.ps1 +++ b/functions/public/Invoke-WPFUnInstall.ps1 @@ -1,7 +1,7 @@ function Invoke-WPFUnInstall { param( [Parameter(Mandatory=$false)] - [PSObject[]]$PackagesToUninstall = $($sync.selectedApps | Foreach-Object { $SortedAppsHashtable.$_ }) + [PSObject[]]$PackagesToUninstall = $($sync.selectedApps | Foreach-Object { $sync.configs.applicationsHashtable.$_ }) ) <# diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 8e473ad230..0e08235870 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -114,34 +114,20 @@ 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 } -$sortedProperties | ForEach-Object { - $SortedAppsHashtable[$_.Name] = $_.Value + +$sync.configs.applicationsHashtable = @{} +$sync.configs.applications.PSObject.Properties | ForEach-Object { + $sync.configs.applicationsHashtable[$_.Name] = $_.Value } # 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-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 -$sync.SortbyCategory.Add_Checked({ - Write-Host "Sort By Category" - $sync.Form.Dispatcher.BeginInvoke([System.Windows.Threading.DispatcherPriority]::Background, [action]{ - Invoke-WPFUIApps -Apps $SortedAppsHashtable -targetGridName "appspanel" - }) | Out-Null -}) -$sync.SortbyAlphabet.Add_Checked({ - Write-Host "Sort By Alphabet" - $sync.Form.Dispatcher.BeginInvoke([System.Windows.Threading.DispatcherPriority]::Background, [action]{ - Invoke-WPFUIApps -Apps $SortedAppsHashtable -targetGridName "appspanel" -alphabetical $true - }) -}) - #=========================================================================== # Store Form Objects In PowerShell #=========================================================================== diff --git a/scripts/start.ps1 b/scripts/start.ps1 index 68bbb947ff..fc0e486237 100644 --- a/scripts/start.ps1 +++ b/scripts/start.ps1 @@ -37,11 +37,13 @@ $sync = [Hashtable]::Synchronized(@{}) $sync.PSScriptRoot = $PSScriptRoot $sync.version = "#{replaceme}" $sync.configs = @{} +$sync.Buttons = @{} $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." $argList = @()