last fixes

remove bitmap
remove unneeded "| out-null"
This commit is contained in:
MyDrift 2024-07-16 20:57:47 +02:00
parent d9b085d316
commit 2fab47dd13
2 changed files with 6 additions and 39 deletions

View File

@ -29,7 +29,7 @@ function Set-WinUtilTaskbaritem {
- Set-WinUtilTaskbaritem -overlay "warning" - Set-WinUtilTaskbaritem -overlay "warning"
No overlay: No overlay:
- Set-WinUtilTaskbaritem -overlay "None" - Set-WinUtilTaskbaritem -overlay "None"
Custom icon: Custom icon (needs to be supported by WPF):
- Set-WinUtilTaskbaritem -overlay "C:\path\to\icon.png" - Set-WinUtilTaskbaritem -overlay "C:\path\to\icon.png"
.PARAMETER description .PARAMETER description
@ -43,39 +43,6 @@ function Set-WinUtilTaskbaritem {
[string]$description [string]$description
) )
# TODO: Make a better solution for this function, accessing problem when calling Set-WinUtilTaskbaritem inside a runspace. Future me or other contributors, please fix this.
function ConvertTo-Bitmap {
<#
.SYNOPSIS
Converts an image file to a Bitmap object
.PARAMETER image
The path to the image file to convert
.EXAMPLE
ConvertTo-Bitmap -imageFilePath "C:\path\to\image.png"
#>
param (
$imageFilePath
)
# Read the image file as a byte array
$imageBytes = [System.IO.File]::ReadAllBytes($imageFilePath)
# Convert the byte array to a Base64 string
$base64String = [System.Convert]::ToBase64String($imageBytes)
# Create a streaming image by streaming the base64 string to a bitmap streamsource
$bitmap = New-Object System.Windows.Media.Imaging.BitmapImage
$bitmap.BeginInit()
$bitmap.StreamSource = [System.IO.MemoryStream][System.Convert]::FromBase64String($base64String)
$bitmap.EndInit()
$bitmap.Freeze()
# Return the bitmap object
return $bitmap
}
if ($value) { if ($value) {
$sync["Form"].taskbarItemInfo.ProgressValue = $value $sync["Form"].taskbarItemInfo.ProgressValue = $value
} }
@ -94,20 +61,20 @@ function Set-WinUtilTaskbaritem {
if ($overlay) { if ($overlay) {
switch ($overlay) { switch ($overlay) {
'logo' { 'logo' {
$sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -imageFilePath "$env:LOCALAPPDATA\winutil\cttlogo.png") $sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\cttlogo.png"
} }
'checkmark' { 'checkmark' {
$sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -imageFilePath "$env:LOCALAPPDATA\winutil\checkmark.png"]) $sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\checkmark.png"
} }
'warning' { 'warning' {
$sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -imageFilePath "$env:LOCALAPPDATA\winutil\warning.png"]) $sync["Form"].taskbarItemInfo.Overlay = "$env:LOCALAPPDATA\winutil\warning.png"
} }
'None' { 'None' {
$sync["Form"].taskbarItemInfo.Overlay = $null $sync["Form"].taskbarItemInfo.Overlay = $null
} }
default { default {
if (Test-Path $overlay) { if (Test-Path $overlay) {
$sync["Form"].taskbarItemInfo.Overlay = (ConvertTo-Bitmap -image $overlay) $sync["Form"].taskbarItemInfo.Overlay = $overlay
} }
} }
} }

View File

@ -460,7 +460,7 @@ if (-NOT (Test-Path -Path $winutildir["warning.png"])) {
} }
Set-WinUtilTaskbaritem -overlay "logo" | Out-Null Set-WinUtilTaskbaritem -overlay "logo"
$sync["Form"].Add_Activated({ $sync["Form"].Add_Activated({
Set-WinUtilTaskbaritem -overlay "logo" Set-WinUtilTaskbaritem -overlay "logo"