From db521534bc7a4345acb6e262ada163c6e8a4ad73 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Sat, 28 Sep 2024 00:21:22 +0200 Subject: [PATCH] add image support via choco db - add image support via choco db - backup image should be taken from unigetui db - backup backup image is some random package one rn --- functions/public/Invoke-WPFUIElements.ps1 | 30 +++++++++++++++++++++-- scripts/main.ps1 | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/functions/public/Invoke-WPFUIElements.ps1 b/functions/public/Invoke-WPFUIElements.ps1 index 41270958..d4f23cdd 100644 --- a/functions/public/Invoke-WPFUIElements.ps1 +++ b/functions/public/Invoke-WPFUIElements.ps1 @@ -297,7 +297,33 @@ function Invoke-WPFUIElements { $image.Width = 40 $image.Height = 40 $image.Margin = New-Object Windows.Thickness(0, 0, 10, 0) - $image.Source = [Windows.Media.Imaging.BitmapImage]::new([Uri]::new("file:///$env:LOCALAPPDATA/winutil/cttlogo.ico")) + if (-not [string]::IsNullOrEmpty($entryInfo.choco)) { + try { + $packageinfo = (choco info $entryInfo.choco --limit-output).Split(' ')[0] + $packageinfo = $packageinfo -replace '\|', '.' + $iconlink = "https://community.chocolatey.org/content/packageimages/" + $packageinfo + $finishediconlink = $iconlink + ".png" + + $webimage = Invoke-WebRequest -Uri $finishediconlink -Method Head -ErrorAction SilentlyContinue + + if ($webimage.StatusCode -eq 200) { + $image.Source = [Windows.Media.Imaging.BitmapImage]::new([Uri]::new($finishediconlink)) + } else { + $finishediconlink = $iconlink + ".svg" + $image.Source = $noimage + } + + } catch { + $image.Source = $noimage + } + } else { + $image.Source = $noimage + } + $image.Clip = New-Object Windows.Media.RectangleGeometry + $image.Clip.Rect = New-Object Windows.Rect(0, 0, $image.Width, $image.Height) + $image.Clip.RadiusX = 5 + $image.Clip.RadiusY = 5 + $imageAndNamePanel.Children.Add($image) | Out-Null # Create the TextBlock for the application name (bigger and bold) @@ -345,7 +371,7 @@ function Invoke-WPFUIElements { $button2.Height = 35 $uninstallIcon = New-Object Windows.Controls.TextBlock - $uninstallIcon.Text = [char]0xE10A # Uninstall Icon + $uninstallIcon.Text = [char]0xE74D # Uninstall Icon $uninstallIcon.FontFamily = "Segoe MDL2 Assets" $uninstallIcon.FontSize = 20 $uninstallIcon.Foreground = $theme.MainForegroundColor diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 74ec8df6..5e0df64a 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -112,6 +112,8 @@ $sync.Form.Add_Loaded({ Invoke-WinutilThemeChange -init $true # Load the configuration files +$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