Skip to content

Commit

Permalink
Remove Alphabetical List, Sort Apps inside Category Alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
Marterich committed Oct 14, 2024
1 parent a839acd commit dcf752f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 62 deletions.
18 changes: 0 additions & 18 deletions config/appnavigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion functions/public/Invoke-WPFInstall.ps1
Original file line number Diff line number Diff line change
@@ -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.$_ })
)
<#
Expand Down
2 changes: 1 addition & 1 deletion functions/public/Invoke-WPFSelectedLabelUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
35 changes: 13 additions & 22 deletions functions/public/Invoke-WPFUIApps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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..."
Expand All @@ -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
}
}
})
Expand Down Expand Up @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion functions/public/Invoke-WPFUnInstall.ps1
Original file line number Diff line number Diff line change
@@ -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.$_ })
)
<#
Expand Down
24 changes: 5 additions & 19 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
#===========================================================================
Expand Down
2 changes: 2 additions & 0 deletions scripts/start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @()
Expand Down

0 comments on commit dcf752f

Please sign in to comment.