Skip to content

Commit

Permalink
Changing trayicon battery level number color to AccentColor to fix re…
Browse files Browse the repository at this point in the history
…adability issues on Windows
  • Loading branch information
YexuanXiao committed Jun 19, 2024
1 parent 4b7e00e commit 2ddddec
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions GalaxyBudsClient/Utils/Interface/WindowIconRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ namespace GalaxyBudsClient.Utils.Interface;
public static class WindowIconRenderer
{
private static readonly WindowIcon DefaultIcon = MakeDefaultIcon();

public static void UpdateDynamicIcon(IBasicStatusUpdate status)
{
var trayIcons = TrayIcon.GetIcons(Application.Current!);
if (trayIcons == null)
if (trayIcons == null)
return;

var batteryLeft = status.BatteryL;
var batteryRight = status.BatteryR;

// Ignore battery level of disconnected earbuds
if (batteryLeft <= 0)
batteryLeft = batteryRight;
if (batteryRight <= 0)
batteryRight = batteryLeft;

int? level = Settings.Data.DynamicTrayIconMode switch
{
DynamicTrayIconModes.BatteryMin => Math.Min(batteryLeft, batteryLeft),
Expand Down Expand Up @@ -67,15 +67,15 @@ private static WindowIcon MakeFromBatteryLevel(int level)
$"{level}",
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
Typeface.Default,
210,
Typeface.Default,
210,
Brushes.Black // This brush does not matter since we use the geometry of the text.
);

// Build the geometry object that represents the text.
var textGeometry = formattedText.BuildGeometry(new Point(0, -30));
var render = new RenderTargetBitmap(new PixelSize(256, 256), new Vector(96, 96));

using (var ctx = render.CreateDrawingContext())
{
ctx.PushRenderOptions(new RenderOptions
Expand All @@ -85,11 +85,10 @@ private static WindowIcon MakeFromBatteryLevel(int level)
EdgeMode = EdgeMode.Antialias,
RequiresFullOpacityHandling = true
});

var fillColor = PlatformUtils.IsOSX ? Brushes.Black : Brushes.White;
ctx.DrawGeometry(fillColor, new Pen(Brushes.Transparent, 0), textGeometry!);

ctx.DrawGeometry(new SolidColorBrush(Settings.Data.AccentColor), new Pen(Brushes.Transparent, 0), textGeometry!);
}

return new WindowIcon(render);
}

Expand Down

0 comments on commit 2ddddec

Please sign in to comment.