From 5b0ea0b3733262cf1c317f3660e2176c3785e4be Mon Sep 17 00:00:00 2001 From: MyDrift Date: Sat, 28 Sep 2024 13:40:38 +0200 Subject: [PATCH] cleanup & remove nav from search effects --- config/appnavigation.json | 54 ++++++++++++++ functions/public/Invoke-WPFUIElements.ps1 | 3 +- scripts/main.ps1 | 86 ++--------------------- 3 files changed, 59 insertions(+), 84 deletions(-) create mode 100644 config/appnavigation.json diff --git a/config/appnavigation.json b/config/appnavigation.json new file mode 100644 index 00000000..d6630a43 --- /dev/null +++ b/config/appnavigation.json @@ -0,0 +1,54 @@ +{ + "WingetRadioButton": { + "Content": "Winget", + "Category": "__Package Manager", + "Type": "RadioButton", + "GroupName": "PackageManagerGroup", + "Checked": true, + "Order": "1", + "Description": "Use Winget for package management" + }, + "ChocoRadioButton": { + "Content": "Chocolatey", + "Category": "__Package Manager", + "Type": "RadioButton", + "GroupName": "PackageManagerGroup", + "Checked": false, + "Order": "2", + "Description": "Use Chocolatey for package management" + }, + "autofallback": { + "Content": "Auto Fallback", + "Category": "__Package Manager", + "Checked": true, + "Order": "3", + "Description": "If the selected package manager fails, automatically switch to the other one" + }, + "DefaultScope": { + "Content": "Default", + "Category": "_Installation Scope", + "Type": "RadioButton", + "GroupName": "InstallationScopeGroup", + "Checked": true, + "Order": "1", + "Description": "Use the default scope of the application" + }, + "UserScope": { + "Content": "User", + "Category": "_Installation Scope", + "Type": "RadioButton", + "GroupName": "InstallationScopeGroup", + "Checked": false, + "Order": "2", + "Description": "If possible, install the application only for the current user" + }, + "GlobalMachineScope": { + "Content": "Global (Machine)", + "Category": "_Installation Scope", + "Type": "RadioButton", + "GroupName": "InstallationScopeGroup", + "Checked": false, + "Order": "3", + "Description": "If possible, install the application globally for all users" + } +} diff --git a/functions/public/Invoke-WPFUIElements.ps1 b/functions/public/Invoke-WPFUIElements.ps1 index a617acff..150c5c9f 100644 --- a/functions/public/Invoke-WPFUIElements.ps1 +++ b/functions/public/Invoke-WPFUIElements.ps1 @@ -172,7 +172,6 @@ function Invoke-WPFUIElements { $image.Height = 40 $image.Margin = New-Object Windows.Thickness(0, 0, 10, 0) $image.Source = $noimage - # TODO: use UniGetUI's image db as a fallback if (-not [string]::IsNullOrEmpty($kaka)) { # replace kaka with $entryInfo.choco to get images, takes a lot longer but works for many packages try { $packageinfo = (choco info $entryInfo.choco --limit-output).Split(' ')[0] @@ -183,7 +182,7 @@ function Invoke-WPFUIElements { if ($webimage.StatusCode -eq 200) { $image.Source = [Windows.Media.Imaging.BitmapImage]::new([Uri]::new($finishediconlink)) } else { - $finishediconlink = $iconlink + ".svg" + # TODO: use UniGetUI's image db as a fallback $image.Source = $noimage } } catch { diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 5e0df64a..5462c1eb 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -115,8 +115,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)) -Invoke-WPFUIElements -configVariable $sync.configs.applications -targetGridName "appspanel" -columncount 1 - # Extract unique categories from the applications configuration $uniqueCategories = $sync.configs.applications.PSObject.Properties.Value | Where-Object { $_.Category } | @@ -131,91 +129,15 @@ foreach ($category in $uniqueCategories) { $categoryConfig[$sanitizedCategoryName] = [PSCustomObject]@{ Category = "Categories" - Content = $category # Keep original category name for display + Content = $category } -} - -# Adding dynamically two radiobuttons for "Package Manager" category with GroupName -$packageManagerConfig = @{ - "WPFWingetRadioButton" = [PSCustomObject]@{ - Name = "WingetRadioButton" - Content = "Winget" - Category = "__Package Manager" - Type = "RadioButton" - GroupName = "PackageManagerGroup" - Checked = $true - Order = "1" - Description = "Use Winget for package management" - } - "WPFChocoRadioButton" = [PSCustomObject]@{ - Name = "ChocoRadioButton" - Content = "Chocolatey" - Category = "__Package Manager" - Type = "RadioButton" - GroupName = "PackageManagerGroup" - Checked = $false - Order = "2" - Description = "Use Chocolatey for package management" - } - "WPFautofallback" = [PSCustomObject]@{ - Name = "AutoRadioButton" - Content = "Auto Fallback" - Category = "__Package Manager" - Checked = $true - Order = "3" - Description = "If the selected package manager fails, automatically switch to the other one" - } - "WPFDefaultScope" = [PSCustomObject]@{ - Name = "DefaultScope" - Content = "Default" - Category = "_Installation Scope" - Type = "RadioButton" - GroupName = "InstallationScopeGroup" - Checked = $true - Order = "1" - Description = "Use the default scope of the application" - } - "WPFUserScope" = [PSCustomObject]@{ - Name = "UserScope" - Content = "User" - Category = "_Installation Scope" - Type = "RadioButton" - GroupName = "InstallationScopeGroup" - Checked = $false - Order = "2" - Description = "If possible, install the application only for the current user" - } - "WPFGlobalMachineScope" = [PSCustomObject]@{ - Name = "GlobalMachineScope" - Content = "Global (Machine)" - Category = "_Installation Scope" - Type = "RadioButton" - GroupName = "InstallationScopeGroup" - Checked = $false - Order = "3" - Description = "If possible, install the application globally for all users" - } -} - -# Merge the packageManagerConfig with the existing category config -$finalConfig = @{} -$categoryConfig.Keys | ForEach-Object { - $finalConfig[$_] = $categoryConfig[$_] -} -$packageManagerConfig.Keys | ForEach-Object { - $finalConfig[$_] = $packageManagerConfig[$_] -} - -# Convert to PSCustomObject for function input -$finalConfigObject = [PSCustomObject]@{} -$finalConfig.Keys | ForEach-Object { - Add-Member -InputObject $finalConfigObject -MemberType NoteProperty -Name $_ -Value $finalConfig[$_] + $sync.configs.appnavigation | Add-Member -MemberType NoteProperty -Name $sanitizedCategoryName -Value $categoryConfig[$sanitizedCategoryName] -Force } # Now call the function with the final merged config -Invoke-WPFUIElements -configVariable $finalConfigObject -targetGridName "appscategory" -columncount 1 - +Invoke-WPFUIElements -configVariable $sync.configs.appnavigation -targetGridName "appscategory" -columncount 1 +Invoke-WPFUIElements -configVariable $sync.configs.applications -targetGridName "appspanel" -columncount 1 Invoke-WPFUIElements -configVariable $sync.configs.tweaks -targetGridName "tweakspanel" -columncount 2 Invoke-WPFUIElements -configVariable $sync.configs.feature -targetGridName "featurespanel" -columncount 2