ai-battery 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,9 @@ param(
7
7
  [string]$BatteryCommandBase64 = "",
8
8
  [string]$InitialJsonBase64 = "",
9
9
  [int]$Width = 282,
10
+ [string]$Backdrop = $(if ($env:AI_BATTERY_HUD_BACKDROP) { $env:AI_BATTERY_HUD_BACKDROP } elseif ($env:CLAUDEX_BATTERY_HUD_BACKDROP) { $env:CLAUDEX_BATTERY_HUD_BACKDROP } else { "off" }),
11
+ [string]$Text = $(if ($env:AI_BATTERY_HUD_TEXT) { $env:AI_BATTERY_HUD_TEXT } elseif ($env:CLAUDEX_BATTERY_HUD_TEXT) { $env:CLAUDEX_BATTERY_HUD_TEXT } else { "light" }),
12
+ [string]$Transparent = "",
10
13
  [double]$Opacity = $(if ($env:AI_BATTERY_HUD_OPACITY) { [double]$env:AI_BATTERY_HUD_OPACITY } elseif ($env:CLAUDEX_BATTERY_HUD_OPACITY) { [double]$env:CLAUDEX_BATTERY_HUD_OPACITY } else { 1.0 }),
11
14
  [switch]$Locked,
12
15
  [switch]$Movable,
@@ -257,6 +260,8 @@ public static class AiBatteryNative {
257
260
  public const int ProcessPowerThrottling = 4;
258
261
  public const uint PROCESS_POWER_THROTTLING_CURRENT_VERSION = 1;
259
262
  public const uint PROCESS_POWER_THROTTLING_EXECUTION_SPEED = 0x1;
263
+ public const int PROCESS_PER_MONITOR_DPI_AWARE = 2;
264
+ public const int DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = -4;
260
265
  public const int OBJID_WINDOW = 0;
261
266
  public const int GWL_EXSTYLE = -20;
262
267
  public const int WS_EX_TRANSPARENT = 0x20;
@@ -281,6 +286,14 @@ public static class AiBatteryNative {
281
286
  public const UInt32 SWP_NOMOVE = 0x0002;
282
287
  public const UInt32 SWP_NOACTIVATE = 0x0010;
283
288
  public const UInt32 SWP_SHOWWINDOW = 0x0040;
289
+ [DllImport("user32.dll", SetLastError=true)]
290
+ public static extern bool SetProcessDPIAware();
291
+ [DllImport("shcore.dll")]
292
+ public static extern int SetProcessDpiAwareness(int value);
293
+ [DllImport("user32.dll", SetLastError=true)]
294
+ public static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);
295
+ [DllImport("user32.dll")]
296
+ public static extern uint GetDpiForWindow(IntPtr hWnd);
284
297
  [DllImport("user32.dll")]
285
298
  public static extern IntPtr GetForegroundWindow();
286
299
  [DllImport("user32.dll")]
@@ -325,6 +338,30 @@ public static class AiBatteryNative {
325
338
  "@
326
339
  Add-Type -TypeDefinition $nativeCode
327
340
 
341
+ function Enable-HudDpiAwareness {
342
+ try {
343
+ $context = [IntPtr]::new([AiBatteryNative]::DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)
344
+ if ([AiBatteryNative]::SetProcessDpiAwarenessContext($context)) { return "per-monitor-v2" }
345
+ } catch {
346
+ # Fall through to older Windows APIs.
347
+ }
348
+
349
+ try {
350
+ if ([AiBatteryNative]::SetProcessDpiAwareness([AiBatteryNative]::PROCESS_PER_MONITOR_DPI_AWARE) -eq 0) { return "per-monitor" }
351
+ } catch {
352
+ # Fall through to system DPI awareness.
353
+ }
354
+
355
+ try {
356
+ if ([AiBatteryNative]::SetProcessDPIAware()) { return "system" }
357
+ } catch {
358
+ # DPI awareness is a quality improvement; the HUD can still run without it.
359
+ }
360
+
361
+ return "default"
362
+ }
363
+ $script:hudDpiAwareness = Enable-HudDpiAwareness
364
+
328
365
  function Disable-ProcessPowerThrottling {
329
366
  # When a fullscreen app is in the foreground, Windows applies EcoQoS power
330
367
  # throttling to background processes like this HUD, which stretches the
@@ -427,15 +464,44 @@ function Get-PercentColor([Nullable[int]]$Percent) {
427
464
  return [System.Drawing.Color]::FromArgb(80, 220, 120)
428
465
  }
429
466
 
430
- function Get-ActivityColor($Result) {
431
- if ($Result -and $Result.running) { return [System.Drawing.Color]::FromArgb(235, 235, 235) }
467
+ function Test-HudDarkText {
468
+ $normalized = ([string]$Text).Trim().ToLowerInvariant()
469
+ return @("dark", "black", "ink", "light-taskbar", "lightbar") -contains $normalized
470
+ }
471
+
472
+ function Get-HudActiveTextColor {
473
+ if ($script:hudDarkText) { return [System.Drawing.Color]::FromArgb(28, 28, 28) }
474
+ return [System.Drawing.Color]::FromArgb(235, 235, 235)
475
+ }
476
+
477
+ function Get-HudMutedTextColor {
478
+ if ($script:hudDarkText) { return [System.Drawing.Color]::FromArgb(88, 88, 88) }
432
479
  return [System.Drawing.Color]::FromArgb(145, 145, 145)
433
480
  }
434
481
 
435
- function Get-DividerColor {
482
+ function Get-HudDividerColor {
483
+ if ($script:hudDarkText) { return [System.Drawing.Color]::FromArgb(100, 100, 100) }
436
484
  return [System.Drawing.Color]::FromArgb(132, 132, 132)
437
485
  }
438
486
 
487
+ function Get-HudBatteryTextColor([bool]$Running) {
488
+ if ($script:hudDarkText) {
489
+ if ($Running) { return [System.Drawing.Color]::FromArgb(20, 20, 20) }
490
+ return [System.Drawing.Color]::FromArgb(78, 78, 78)
491
+ }
492
+ if ($Running) { return [System.Drawing.Color]::FromArgb(255, 255, 255) }
493
+ return [System.Drawing.Color]::FromArgb(235, 235, 235)
494
+ }
495
+
496
+ function Get-ActivityColor($Result) {
497
+ if ($Result -and $Result.running) { return Get-HudActiveTextColor }
498
+ return Get-HudMutedTextColor
499
+ }
500
+
501
+ function Get-DividerColor {
502
+ return Get-HudDividerColor
503
+ }
504
+
439
505
  function Format-Parts($Result, [string]$Name) {
440
506
  $isRunning = [bool]($Result -and $Result.running)
441
507
  $textColor = Get-ActivityColor $Result
@@ -685,7 +751,96 @@ if ($Once) {
685
751
 
686
752
  Add-Type -AssemblyName System.Windows.Forms
687
753
  Add-Type -AssemblyName System.Drawing
754
+ try {
755
+ [System.Windows.Forms.Application]::SetHighDpiMode([System.Windows.Forms.HighDpiMode]::PerMonitorV2) | Out-Null
756
+ } catch {
757
+ # Windows PowerShell/.NET Framework does not expose SetHighDpiMode; the
758
+ # native DPI awareness call above covers that runtime.
759
+ }
688
760
  [System.Windows.Forms.Application]::EnableVisualStyles()
761
+ try {
762
+ [System.Windows.Forms.Application]::SetCompatibleTextRenderingDefault($false)
763
+ } catch {
764
+ # The default is already GDI text rendering on older WinForms.
765
+ }
766
+
767
+ function Get-HudDpi {
768
+ try {
769
+ if ($form -and -not $form.IsDisposed -and $form.Handle -ne [IntPtr]::Zero) {
770
+ $windowDpi = [AiBatteryNative]::GetDpiForWindow($form.Handle)
771
+ if ($windowDpi -gt 0) { return [int]$windowDpi }
772
+ }
773
+ } catch {
774
+ # Fall back to the desktop graphics DPI below.
775
+ }
776
+
777
+ $graphics = $null
778
+ try {
779
+ $graphics = [System.Drawing.Graphics]::FromHwnd([IntPtr]::Zero)
780
+ if ($graphics.DpiX -gt 0) { return [int][math]::Round($graphics.DpiX) }
781
+ } catch {
782
+ # Use the WinForms baseline when the desktop DPI cannot be queried.
783
+ } finally {
784
+ if ($graphics) { $graphics.Dispose() }
785
+ }
786
+
787
+ return 96
788
+ }
789
+
790
+ function Update-HudDpiScale {
791
+ $dpi = [math]::Max(96, (Get-HudDpi))
792
+ $script:hudDpi = [int]$dpi
793
+ $script:hudScale = [double]$script:hudDpi / 96.0
794
+ }
795
+
796
+ function Scale-HudValue([double]$Value) {
797
+ if ($Value -eq 0) { return 0 }
798
+ $scaled = [int][math]::Round($Value * $script:hudScale)
799
+ if ($Value -gt 0) { return [math]::Max(1, $scaled) }
800
+ return $scaled
801
+ }
802
+
803
+ function New-HudPadding([int]$Left, [int]$Top, [int]$Right, [int]$Bottom) {
804
+ return [System.Windows.Forms.Padding]::new(
805
+ (Scale-HudValue $Left),
806
+ (Scale-HudValue $Top),
807
+ (Scale-HudValue $Right),
808
+ (Scale-HudValue $Bottom)
809
+ )
810
+ }
811
+
812
+ function New-HudBitmapSurface([int]$Width, [int]$Height) {
813
+ $scale = [math]::Max(1.0, [double]$script:hudScale)
814
+ $bitmapWidth = [math]::Max(1, [int][math]::Round($Width * $scale))
815
+ $bitmapHeight = [math]::Max(1, [int][math]::Round($Height * $scale))
816
+ $bitmap = [System.Drawing.Bitmap]::new($bitmapWidth, $bitmapHeight)
817
+ $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
818
+ if ([math]::Abs($scale - 1.0) -gt 0.001) {
819
+ $graphics.ScaleTransform([single]$scale, [single]$scale)
820
+ }
821
+ return @{
822
+ Bitmap = $bitmap
823
+ Graphics = $graphics
824
+ }
825
+ }
826
+
827
+ function Test-HudTransparentSurface {
828
+ $value = $Transparent
829
+ if (-not $value) { $value = $env:AI_BATTERY_HUD_TRANSPARENT }
830
+ if (-not $value) { $value = $env:CLAUDEX_BATTERY_HUD_TRANSPARENT }
831
+ if (-not $value) { return $true }
832
+ $normalized = ([string]$value).Trim().ToLowerInvariant()
833
+ return -not (@("0", "false", "no", "off", "solid") -contains $normalized)
834
+ }
835
+
836
+ function Test-HudContrastBackdrop {
837
+ $normalized = ([string]$Backdrop).Trim().ToLowerInvariant()
838
+ if (-not $normalized) { $normalized = "off" }
839
+ return @("1", "true", "yes", "on", "solid", "backdrop") -contains $normalized
840
+ }
841
+
842
+ Update-HudDpiScale
843
+ $script:hudDarkText = Test-HudDarkText
689
844
 
690
845
  function Get-LineText($Parts) {
691
846
  return "$($Parts.Prefix)[battery]$($Parts.Suffix)"
@@ -724,8 +879,8 @@ function New-ProviderTrayIcon([string]$ProviderLabel, [Nullable[int]]$Percent, [
724
879
  $graphics.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::AntiAliasGridFit
725
880
  $graphics.Clear([System.Drawing.Color]::Transparent)
726
881
 
727
- $outlineColor = [System.Drawing.Color]::FromArgb(232, 232, 232)
728
- $mutedColor = [System.Drawing.Color]::FromArgb(145, 145, 145)
882
+ $outlineColor = [System.Drawing.Color]::FromArgb(170, 170, 170)
883
+ $mutedColor = [System.Drawing.Color]::FromArgb(120, 120, 120)
729
884
  $activeOutlineColor = if ($Running) { $outlineColor } else { $mutedColor }
730
885
  $fillColor = if ($Running) { Get-PercentColor $Percent } else { $mutedColor }
731
886
  $textColor = if ($Running) { [System.Drawing.Color]::FromArgb(245, 245, 245) } else { $mutedColor }
@@ -786,8 +941,8 @@ function New-SingleBatteryTrayIcon([Nullable[int]]$Percent) {
786
941
  $graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
787
942
  $graphics.Clear([System.Drawing.Color]::Transparent)
788
943
 
789
- $outlineColor = [System.Drawing.Color]::FromArgb(232, 232, 232)
790
- $mutedColor = [System.Drawing.Color]::FromArgb(145, 145, 145)
944
+ $outlineColor = [System.Drawing.Color]::FromArgb(170, 170, 170)
945
+ $mutedColor = [System.Drawing.Color]::FromArgb(120, 120, 120)
791
946
  $fillColor = Get-PercentColor $Percent
792
947
  $outlinePen = [System.Drawing.Pen]::new($(if ($null -eq $Percent) { $mutedColor } else { $outlineColor }), 2)
793
948
  $fillBrush = [System.Drawing.SolidBrush]::new($fillColor)
@@ -826,39 +981,52 @@ function New-SingleBatteryTrayIcon([Nullable[int]]$Percent) {
826
981
  return $icon
827
982
  }
828
983
 
829
- function New-BatteryImage([Nullable[int]]$Percent, [bool]$Running = $true, [int]$Width = 34, [int]$Height = 16) {
830
- $bitmap = [System.Drawing.Bitmap]::new($Width, $Height)
831
- $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
984
+ function New-BatteryImage([Nullable[int]]$Percent, [bool]$Running = $true, [int]$Width = 36, [int]$Height = 16, [bool]$DrawText = $true) {
985
+ $surface = New-HudBitmapSurface $Width $Height
986
+ $bitmap = $surface.Bitmap
987
+ $graphics = $surface.Graphics
832
988
  $graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
833
- $graphics.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::AntiAliasGridFit
989
+ $graphics.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::ClearTypeGridFit
990
+ $graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::Half
834
991
  $graphics.Clear([System.Drawing.Color]::Transparent)
835
992
 
836
- $outlineColor = [System.Drawing.Color]::FromArgb(232, 232, 232)
837
- $mutedColor = [System.Drawing.Color]::FromArgb(145, 145, 145)
993
+ $outlineColor = [System.Drawing.Color]::FromArgb(170, 170, 170)
994
+ $mutedColor = [System.Drawing.Color]::FromArgb(120, 120, 120)
995
+ if ($script:hudDarkText) {
996
+ $outlineColor = [System.Drawing.Color]::FromArgb(58, 58, 58)
997
+ $mutedColor = [System.Drawing.Color]::FromArgb(98, 98, 98)
998
+ }
838
999
  $activeOutlineColor = if ($Running) { $outlineColor } else { $mutedColor }
839
1000
  # The fill always keeps its charge color (matching the terminal bar);
840
1001
  # running state is signalled by the outline and text colors instead.
841
1002
  $fillColor = Get-PercentColor $Percent
842
- $outlinePen = [System.Drawing.Pen]::new($(if ($null -eq $Percent) { $mutedColor } else { $activeOutlineColor }), 1.6)
1003
+ $outlinePen = [System.Drawing.Pen]::new($(if ($null -eq $Percent) { $mutedColor } else { $activeOutlineColor }), 1.0)
843
1004
  $fillBrush = [System.Drawing.SolidBrush]::new($fillColor)
844
- # A solid dark interior keeps the desktop from bleeding through the empty
845
- # part of the battery, so the percent text stays readable on any wallpaper.
846
- $interiorBrush = [System.Drawing.SolidBrush]::new([System.Drawing.Color]::FromArgb(46, 46, 46))
1005
+ $interiorColor = if ($script:hudDarkText) {
1006
+ [System.Drawing.Color]::FromArgb(246, 246, 246)
1007
+ } else {
1008
+ # A solid dark interior keeps the desktop from bleeding through the empty
1009
+ # part of the battery, so the percent text stays readable on any wallpaper.
1010
+ [System.Drawing.Color]::FromArgb(46, 46, 46)
1011
+ }
1012
+ $interiorBrush = [System.Drawing.SolidBrush]::new($interiorColor)
847
1013
  $terminalBrush = [System.Drawing.SolidBrush]::new($(if ($null -eq $Percent) { $mutedColor } else { $activeOutlineColor }))
848
- $textBrush = [System.Drawing.SolidBrush]::new($(if ($Running) { [System.Drawing.Color]::FromArgb(250, 250, 250) } else { [System.Drawing.Color]::FromArgb(210, 210, 210) }))
849
- $textHaloBrush = [System.Drawing.SolidBrush]::new([System.Drawing.Color]::FromArgb(200, 15, 15, 15))
850
- $fontSize = if ($null -eq $Percent) { 7.8 } elseif ($Percent -ge 100) { 7.2 } else { 8.2 }
851
- $batteryFont = [System.Drawing.Font]::new("Segoe UI", $fontSize, [System.Drawing.FontStyle]::Bold)
1014
+ $textBrush = [System.Drawing.SolidBrush]::new((Get-HudBatteryTextColor $Running))
1015
+ $batteryText = if ($null -eq $Percent) { "--" } else { [string][int]$Percent }
1016
+ $fontSize = if ($batteryText.Length -ge 3) { 4.4 } elseif ($batteryText.Length -ge 2) { 5.1 } else { 5.8 }
1017
+ $batteryFont = $null
852
1018
  $centerFormat = [System.Drawing.StringFormat]::new()
853
1019
  $centerFormat.Alignment = [System.Drawing.StringAlignment]::Center
854
1020
  $centerFormat.LineAlignment = [System.Drawing.StringAlignment]::Center
1021
+ $centerFormat.Trimming = [System.Drawing.StringTrimming]::None
1022
+ $centerFormat.FormatFlags = [System.Drawing.StringFormatFlags]::NoWrap
855
1023
 
856
1024
  try {
857
1025
  $bodyX = 1
858
1026
  $bodyY = 3
859
1027
  $bodyW = $Width - 6
860
1028
  $bodyH = $Height - 6
861
- $capW = 3
1029
+ $capW = 2
862
1030
  $capH = [math]::Max(4, [math]::Floor($bodyH / 2))
863
1031
  $capY = $bodyY + [math]::Floor(($bodyH - $capH) / 2)
864
1032
 
@@ -875,23 +1043,26 @@ function New-BatteryImage([Nullable[int]]$Percent, [bool]$Running = $true, [int]
875
1043
  if ($clamped -gt 0 -and $fillW -lt 2) { $fillW = 2 }
876
1044
  $graphics.FillRectangle($fillBrush, $bodyX + 3, $bodyY + 3, $fillW, $bodyH - 5)
877
1045
  }
878
- $batteryText = if ($null -eq $Percent) { "--" } else { [string][int]$Percent }
879
- $textRect = [System.Drawing.RectangleF]::new($bodyX + 2, $bodyY, $bodyW - 3, $bodyH + 1)
880
- # A one-pixel dark halo keeps the number legible over the green/orange/red
881
- # fill as well as over the dark empty region.
882
- foreach ($shift in @(@(-1, 0), @(1, 0), @(0, -1), @(0, 1))) {
883
- $haloRect = [System.Drawing.RectangleF]::new($textRect.X + $shift[0], $textRect.Y + $shift[1], $textRect.Width, $textRect.Height)
884
- $graphics.DrawString($batteryText, $batteryFont, $textHaloBrush, $haloRect, $centerFormat)
1046
+ if ($DrawText) {
1047
+ $textRect = [System.Drawing.RectangleF]::new($bodyX + 3, $bodyY + 2.5, $bodyW - 6, $bodyH - 4)
1048
+ do {
1049
+ if ($batteryFont) { $batteryFont.Dispose() }
1050
+ $fontFamily = if ($font) { $font.FontFamily.Name } else { "Segoe UI" }
1051
+ $batteryFont = [System.Drawing.Font]::new($fontFamily, $fontSize, [System.Drawing.FontStyle]::Regular)
1052
+ $textSize = $graphics.MeasureString($batteryText, $batteryFont)
1053
+ if ($textSize.Width -le ($textRect.Width + 1) -or $fontSize -le 4.0) { break }
1054
+ $fontSize -= 0.4
1055
+ } while ($true)
1056
+
1057
+ $graphics.DrawString($batteryText, $batteryFont, $textBrush, $textRect, $centerFormat)
885
1058
  }
886
- $graphics.DrawString($batteryText, $batteryFont, $textBrush, $textRect, $centerFormat)
887
1059
  } finally {
888
1060
  $outlinePen.Dispose()
889
1061
  $fillBrush.Dispose()
890
1062
  $interiorBrush.Dispose()
891
1063
  $terminalBrush.Dispose()
892
1064
  $textBrush.Dispose()
893
- $textHaloBrush.Dispose()
894
- $batteryFont.Dispose()
1065
+ if ($batteryFont) { $batteryFont.Dispose() }
895
1066
  $centerFormat.Dispose()
896
1067
  $graphics.Dispose()
897
1068
  }
@@ -913,7 +1084,7 @@ function New-StatusMenuLabel($Font, [int]$Width, $Align = [System.Drawing.Conten
913
1084
 
914
1085
  function New-StatusMenuRow($Font) {
915
1086
  $panel = New-Object System.Windows.Forms.FlowLayoutPanel
916
- $panel.Width = 252
1087
+ $panel.Width = 276
917
1088
  $panel.Height = 22
918
1089
  $panel.FlowDirection = [System.Windows.Forms.FlowDirection]::LeftToRight
919
1090
  $panel.WrapContents = $false
@@ -923,14 +1094,14 @@ function New-StatusMenuRow($Font) {
923
1094
 
924
1095
  $name = New-StatusMenuLabel $Font 44
925
1096
  $icon = New-Object System.Windows.Forms.PictureBox
926
- $icon.Width = 36
1097
+ $icon.Width = 40
927
1098
  $icon.Height = 20
928
- $icon.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage
1099
+ $icon.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
929
1100
  $icon.Margin = [System.Windows.Forms.Padding]::new(0)
930
1101
  $icon.BackColor = [System.Drawing.SystemColors]::Menu
931
1102
  $percent = New-StatusMenuLabel $Font 0 ([System.Drawing.ContentAlignment]::MiddleRight)
932
- $reset = New-StatusMenuLabel $Font 58
933
- $week = New-StatusMenuLabel $Font 50
1103
+ $reset = New-StatusMenuLabel $Font 66
1104
+ $week = New-StatusMenuLabel $Font 56
934
1105
  $extra = New-StatusMenuLabel $Font 58
935
1106
 
936
1107
  foreach ($control in @($name, $icon, $percent, $reset, $week, $extra)) {
@@ -1091,16 +1262,32 @@ if ($Mode -eq "tray") {
1091
1262
  $form = New-Object System.Windows.Forms.Form
1092
1263
  $form.Text = "AI Battery"
1093
1264
  $form.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual
1094
- $form.Width = $Width
1095
- $form.Height = if ($Mode -eq "floating") { 44 } elseif ($Mode -eq "statusline") { 44 } else { 54 }
1265
+ $form.Width = Scale-HudValue $Width
1266
+ $form.Height = if ($Mode -eq "floating") { Scale-HudValue 44 } elseif ($Mode -eq "statusline") { Scale-HudValue 44 } else { Scale-HudValue 54 }
1096
1267
  $script:hudTwoRowHeight = $form.Height
1097
- $script:hudOneRowHeight = [math]::Max(20, $form.Height - 18)
1268
+ $script:hudOneRowHeight = [math]::Max((Scale-HudValue 20), $form.Height - (Scale-HudValue 18))
1098
1269
  $form.TopMost = $true
1099
1270
  $form.ShowInTaskbar = $false
1100
1271
  $form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
1101
- $transparentBackColor = [System.Drawing.Color]::FromArgb(18, 18, 18)
1102
- $form.BackColor = $transparentBackColor
1103
- $form.TransparencyKey = $transparentBackColor
1272
+ $script:hudTransparentSurface = Test-HudTransparentSurface
1273
+ $script:hudContrastBackdrop = Test-HudContrastBackdrop
1274
+ $script:hudChromeBackColor = [System.Drawing.Color]::FromArgb(24, 24, 24)
1275
+ if ($script:hudTransparentSurface) {
1276
+ $transparentBackColor = if ($script:hudDarkText -and (-not $script:hudContrastBackdrop)) {
1277
+ [System.Drawing.Color]::FromArgb(254, 254, 254)
1278
+ } else {
1279
+ [System.Drawing.Color]::FromArgb(18, 18, 18)
1280
+ }
1281
+ $form.BackColor = $transparentBackColor
1282
+ $form.TransparencyKey = $transparentBackColor
1283
+ } else {
1284
+ $form.BackColor = $script:hudChromeBackColor
1285
+ }
1286
+ $script:hudSurfaceBackColor = if ($script:hudContrastBackdrop -or (-not $script:hudTransparentSurface)) {
1287
+ $script:hudChromeBackColor
1288
+ } else {
1289
+ $form.BackColor
1290
+ }
1104
1291
  $form.Opacity = [math]::Max(0.2, [math]::Min(1.0, $Opacity))
1105
1292
 
1106
1293
  $font = [System.Drawing.Font]::new("Segoe UI", $(if ($Mode -eq "statusline") { 8.5 } else { 9 }), [System.Drawing.FontStyle]::Regular)
@@ -1112,11 +1299,11 @@ $panel.RowCount = 2
1112
1299
  $panel.ColumnCount = 1
1113
1300
  $panel.GrowStyle = [System.Windows.Forms.TableLayoutPanelGrowStyle]::FixedSize
1114
1301
  $panel.Padding = if ($Mode -eq "floating" -or $Mode -eq "statusline") {
1115
- [System.Windows.Forms.Padding]::new(6, 4, 2, 3)
1302
+ New-HudPadding 6 4 2 3
1116
1303
  } else {
1117
- [System.Windows.Forms.Padding]::new(10, 7, 10, 6)
1304
+ New-HudPadding 10 7 10 6
1118
1305
  }
1119
- $panel.BackColor = $form.BackColor
1306
+ $panel.BackColor = $script:hudSurfaceBackColor
1120
1307
  $panel.RowStyles.Add([System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, 50)) | Out-Null
1121
1308
  $panel.RowStyles.Add([System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, 50)) | Out-Null
1122
1309
  $panel.ColumnStyles.Add([System.Windows.Forms.ColumnStyle]::new([System.Windows.Forms.SizeType]::Percent, 100)) | Out-Null
@@ -1128,7 +1315,7 @@ function New-HudRow {
1128
1315
  $row.WrapContents = $false
1129
1316
  $row.Margin = [System.Windows.Forms.Padding]::new(0)
1130
1317
  $row.Padding = [System.Windows.Forms.Padding]::new(0)
1131
- $row.BackColor = $form.BackColor
1318
+ $row.BackColor = $script:hudSurfaceBackColor
1132
1319
  return $row
1133
1320
  }
1134
1321
 
@@ -1136,42 +1323,71 @@ function New-HudLabel([int]$RightMargin = 0) {
1136
1323
  $label = New-Object System.Windows.Forms.Label
1137
1324
  $label.AutoSize = $false
1138
1325
  $label.Width = 0
1139
- $label.Height = 18
1326
+ $label.Height = Scale-HudValue 18
1140
1327
  $label.Font = $font
1141
1328
  $label.UseCompatibleTextRendering = $false
1142
- $label.BackColor = $form.BackColor
1143
- $label.Margin = [System.Windows.Forms.Padding]::new(0, 0, $RightMargin, 0)
1329
+ $label.BackColor = $script:hudSurfaceBackColor
1330
+ $label.Margin = New-HudPadding 0 0 $RightMargin 0
1144
1331
  $label.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
1145
1332
  return $label
1146
1333
  }
1147
1334
 
1148
1335
  function New-HudIconBox {
1149
1336
  $box = New-Object System.Windows.Forms.PictureBox
1150
- $box.Width = 36
1151
- $box.Height = 18
1152
- $box.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage
1153
- $box.BackColor = $form.BackColor
1154
- $box.Margin = [System.Windows.Forms.Padding]::new(0, 0, 2, 0)
1337
+ $box.Width = Scale-HudValue 40
1338
+ $box.Height = Scale-HudValue 18
1339
+ $box.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
1340
+ $box.BackColor = $script:hudSurfaceBackColor
1341
+ $box.ForeColor = Get-HudBatteryTextColor $true
1342
+ $box.Margin = New-HudPadding 0 0 2 0
1343
+ $box.add_Paint({
1344
+ param($sender, $event)
1345
+ $text = [string]$sender.AccessibleName
1346
+ if ([string]::IsNullOrWhiteSpace($text)) { return }
1347
+
1348
+ $drawFont = $null
1349
+ $disposeDrawFont = $false
1350
+ try {
1351
+ $drawFont = $font
1352
+ if (-not $drawFont) {
1353
+ $drawFont = [System.Drawing.Font]::new("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)
1354
+ $disposeDrawFont = $true
1355
+ }
1356
+ $rect = [System.Drawing.Rectangle]::new(
1357
+ (Scale-HudValue 2),
1358
+ 0,
1359
+ [math]::Max(1, $sender.Width - (Scale-HudValue 4)),
1360
+ $sender.Height
1361
+ )
1362
+ $flags = [System.Windows.Forms.TextFormatFlags]::HorizontalCenter -bor
1363
+ [System.Windows.Forms.TextFormatFlags]::VerticalCenter -bor
1364
+ [System.Windows.Forms.TextFormatFlags]::SingleLine -bor
1365
+ [System.Windows.Forms.TextFormatFlags]::NoPadding
1366
+ [System.Windows.Forms.TextRenderer]::DrawText($event.Graphics, $text, $drawFont, $rect, $sender.ForeColor, $flags)
1367
+ } finally {
1368
+ if ($disposeDrawFont -and $drawFont) { $drawFont.Dispose() }
1369
+ }
1370
+ })
1155
1371
  return $box
1156
1372
  }
1157
1373
 
1158
1374
  function New-HudLineIconBox {
1159
1375
  $box = New-Object System.Windows.Forms.PictureBox
1160
- $box.Width = 21
1161
- $box.Height = 18
1376
+ $box.Width = Scale-HudValue 21
1377
+ $box.Height = Scale-HudValue 18
1162
1378
  $box.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage
1163
- $box.BackColor = $form.BackColor
1164
- $box.Margin = [System.Windows.Forms.Padding]::new(3, 0, 0, 0)
1379
+ $box.BackColor = $script:hudSurfaceBackColor
1380
+ $box.Margin = New-HudPadding 3 0 0 0
1165
1381
  return $box
1166
1382
  }
1167
1383
 
1168
1384
  function New-HudDivider {
1169
1385
  $divider = New-Object System.Windows.Forms.Panel
1170
1386
  $divider.AutoSize = $false
1171
- $divider.Width = 1
1172
- $divider.Height = 12
1387
+ $divider.Width = Scale-HudValue 1
1388
+ $divider.Height = Scale-HudValue 12
1173
1389
  $divider.BackColor = Get-DividerColor
1174
- $divider.Margin = [System.Windows.Forms.Padding]::new(4, 3, 4, 3)
1390
+ $divider.Margin = New-HudPadding 4 3 4 3
1175
1391
  return $divider
1176
1392
  }
1177
1393
 
@@ -1194,21 +1410,41 @@ $claudeExtraLabel = New-HudLabel
1194
1410
 
1195
1411
  foreach ($label in @($codexPrefixLabel, $claudePrefixLabel)) {
1196
1412
  $label.AutoSize = $false
1197
- $label.Width = 48
1413
+ $label.Width = Scale-HudValue 48
1198
1414
  }
1199
1415
  foreach ($label in @($codexIconLabel, $claudeIconLabel)) {
1200
- $label.Width = 38
1416
+ $label.Width = Scale-HudValue 42
1201
1417
  }
1202
1418
 
1203
1419
  $codexHudControls = @($codexPrefixLabel, $codexIconLabel, $codexDivider1, $codexResetLabel, $codexDivider2, $codexWeekLabel, $codexExtraLabel)
1204
1420
  $claudeHudControls = @($claudePrefixLabel, $claudeIconLabel, $claudeDivider1, $claudeResetLabel, $claudeDivider2, $claudeWeekLabel, $claudeExtraLabel)
1205
1421
 
1422
+ function Test-PointInBounds($Bounds, [System.Drawing.Point]$Point) {
1423
+ if (-not $Bounds) { return $false }
1424
+ return $Bounds.Contains($Point)
1425
+ }
1426
+
1206
1427
  $menu = New-Object System.Windows.Forms.ContextMenuStrip
1207
1428
  $menu.Font = $font
1429
+ $menu.AutoClose = $true
1430
+ $script:hudMenuOpenedAt = [datetime]::UtcNow
1431
+ $script:hudMenuLastInsideAt = [datetime]::UtcNow
1432
+ $script:hudMenuReadyForOutsideClick = $false
1208
1433
  $exitItem = $menu.Items.Add("Exit")
1209
1434
  $exitItem.add_Click({ $form.Close() })
1435
+ $menu.add_Opened({
1436
+ $script:hudMenuOpenedAt = [datetime]::UtcNow
1437
+ $script:hudMenuLastInsideAt = [datetime]::UtcNow
1438
+ $script:hudMenuReadyForOutsideClick = $false
1439
+ })
1440
+ function Hide-HudMenu {
1441
+ if ($menu -and -not $menu.IsDisposed -and $menu.Visible) {
1442
+ $menu.Close([System.Windows.Forms.ToolStripDropDownCloseReason]::CloseCalled)
1443
+ }
1444
+ }
1210
1445
  $form.ContextMenuStrip = $menu
1211
1446
  $panel.ContextMenuStrip = $menu
1447
+
1212
1448
  foreach ($label in $codexHudControls) {
1213
1449
  $label.ContextMenuStrip = $menu
1214
1450
  $codexRow.Controls.Add($label) | Out-Null
@@ -1224,7 +1460,7 @@ $panel.Controls.Add($claudeRow, 0, 1) | Out-Null
1224
1460
  $form.Controls.Add($panel)
1225
1461
 
1226
1462
  $hitForm = $null
1227
- if (-not $ClickThrough) {
1463
+ if ((-not $ClickThrough) -and $script:hudTransparentSurface) {
1228
1464
  $hitForm = New-Object System.Windows.Forms.Form
1229
1465
  $hitForm.Text = "AI Battery hit area"
1230
1466
  $hitForm.Width = $form.Width
@@ -1581,6 +1817,7 @@ function Ensure-HudTopMost {
1581
1817
  function Set-HudHiddenForFullscreen([bool]$Hidden) {
1582
1818
  $script:hudHiddenForFullscreen = $Hidden
1583
1819
  if ($Hidden) {
1820
+ Hide-HudMenu
1584
1821
  if ($hitForm -and -not $hitForm.IsDisposed -and $hitForm.Visible) {
1585
1822
  [AiBatteryNative]::ShowWindow($hitForm.Handle, [AiBatteryNative]::SW_HIDE) | Out-Null
1586
1823
  $hitForm.Hide()
@@ -1620,6 +1857,38 @@ function Update-HudVisibilityForFullscreen {
1620
1857
 
1621
1858
  $script:fullscreenCheckPending = $false
1622
1859
 
1860
+ function Update-HudMenuAutoHide {
1861
+ if (-not $menu -or $menu.IsDisposed -or -not $menu.Visible) { return }
1862
+ $now = [datetime]::UtcNow
1863
+ $point = [System.Windows.Forms.Cursor]::Position
1864
+ $insideMenu = Test-PointInBounds $menu.Bounds $point
1865
+ $insideHud = Test-PointInBounds $form.Bounds $point
1866
+ if ($hitForm -and -not $hitForm.IsDisposed) {
1867
+ $insideHud = $insideHud -or (Test-PointInBounds $hitForm.Bounds $point)
1868
+ }
1869
+
1870
+ if ($insideMenu -or $insideHud) {
1871
+ $script:hudMenuLastInsideAt = $now
1872
+ }
1873
+
1874
+ $buttons = [System.Windows.Forms.Control]::MouseButtons
1875
+ if (-not $script:hudMenuReadyForOutsideClick) {
1876
+ if ($buttons -eq [System.Windows.Forms.MouseButtons]::None) {
1877
+ $script:hudMenuReadyForOutsideClick = $true
1878
+ }
1879
+ return
1880
+ }
1881
+
1882
+ if ($buttons -ne [System.Windows.Forms.MouseButtons]::None -and -not $insideMenu) {
1883
+ Hide-HudMenu
1884
+ return
1885
+ }
1886
+
1887
+ if ((-not $insideMenu) -and (-not $insideHud) -and (($now - $script:hudMenuLastInsideAt).TotalMilliseconds -gt 1500)) {
1888
+ Hide-HudMenu
1889
+ }
1890
+ }
1891
+
1623
1892
  function Request-FullscreenCheck {
1624
1893
  if (-not $form -or $form.IsDisposed) { return }
1625
1894
  if ($form.InvokeRequired) {
@@ -1685,15 +1954,19 @@ function Stop-FullscreenEventHooks {
1685
1954
 
1686
1955
  function Set-HudBatteryImage($Box, [Nullable[int]]$Percent, [bool]$Running) {
1687
1956
  $oldImage = $Box.Image
1688
- $Box.Image = New-BatteryImage $Percent $Running
1957
+ $Box.Image = New-BatteryImage $Percent $Running 36 16 $false
1958
+ $Box.AccessibleName = if ($null -eq $Percent) { "--" } else { [string][int]$Percent }
1959
+ $Box.ForeColor = Get-HudBatteryTextColor $Running
1689
1960
  $Box.Visible = $true
1690
1961
  $Box.Tag = $true
1962
+ $Box.Invalidate()
1691
1963
  if ($oldImage) { $oldImage.Dispose() }
1692
1964
  }
1693
1965
 
1694
1966
  function New-HudGlyphImage([string]$Kind, [System.Drawing.Color]$Color, [int]$Width = 21, [int]$Height = 18) {
1695
- $bitmap = [System.Drawing.Bitmap]::new($Width, $Height)
1696
- $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
1967
+ $surface = New-HudBitmapSurface $Width $Height
1968
+ $bitmap = $surface.Bitmap
1969
+ $graphics = $surface.Graphics
1697
1970
  $graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
1698
1971
  $graphics.TextRenderingHint = [System.Drawing.Text.TextRenderingHint]::AntiAliasGridFit
1699
1972
  $graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
@@ -1831,7 +2104,11 @@ function Set-HudMetricLabel($Label, [string]$Value, [System.Drawing.Color]$Color
1831
2104
  $Label.Visible = $false
1832
2105
  $Label.Tag = $false
1833
2106
  } else {
1834
- $Label.Width = if ($null -ne $FixedWidth -and $FixedWidth -gt 0) { [int]$FixedWidth } else { (Get-LabelTextWidth $Label) + 1 }
2107
+ $Label.Width = if ($null -ne $FixedWidth -and $FixedWidth -gt 0) {
2108
+ [int]$FixedWidth
2109
+ } else {
2110
+ (Get-LabelTextWidth $Label) + (Scale-HudValue 1)
2111
+ }
1835
2112
  $Label.Visible = $true
1836
2113
  $Label.Tag = $true
1837
2114
  }
@@ -1844,22 +2121,40 @@ function Set-HudDivider($Divider, [string]$Value) {
1844
2121
  $Divider.Tag = $false
1845
2122
  } else {
1846
2123
  $Divider.Visible = $true
1847
- $Divider.Width = 1
2124
+ $Divider.Width = Scale-HudValue 1
1848
2125
  $Divider.Tag = $true
1849
2126
  }
1850
2127
  }
1851
2128
 
1852
- function Set-HudParts($Parts, $PrefixLabel, $BatteryBox, $Divider1, $ResetLabel, $Divider2, $WeekLabel, $ExtraLabel) {
2129
+ function Get-HudTextWidth([string]$Value, $Font = $font) {
2130
+ if ([string]::IsNullOrWhiteSpace($Value)) { return 0 }
2131
+ return [System.Windows.Forms.TextRenderer]::MeasureText(
2132
+ $Value,
2133
+ $Font,
2134
+ [System.Drawing.Size]::new(1000, 1000),
2135
+ [System.Windows.Forms.TextFormatFlags]::NoPadding
2136
+ ).Width
2137
+ }
2138
+
2139
+ function Get-SharedHudColumnWidth([string[]]$Values, [int]$Minimum = 0) {
2140
+ $width = Scale-HudValue $Minimum
2141
+ foreach ($value in $Values) {
2142
+ $width = [math]::Max($width, (Get-HudTextWidth $value) + (Scale-HudValue 1))
2143
+ }
2144
+ return [int]$width
2145
+ }
2146
+
2147
+ function Set-HudParts($Parts, $PrefixLabel, $BatteryBox, $Divider1, $ResetLabel, $Divider2, $WeekLabel, $ExtraLabel, [Nullable[int]]$ResetWidth = $null, [Nullable[int]]$WeekWidth = $null) {
1853
2148
  $PrefixLabel.Text = $Parts.Prefix
1854
2149
  $PrefixLabel.ForeColor = $Parts.TextColor
1855
- $PrefixLabel.Width = 48
2150
+ $PrefixLabel.Width = Scale-HudValue 48
1856
2151
  $PrefixLabel.Visible = $true
1857
2152
  $PrefixLabel.Tag = $true
1858
2153
  Set-HudBatteryImage $BatteryBox $Parts.Percent $Parts.Running
1859
2154
  Set-HudDivider $Divider1 $Parts.ResetValue
1860
- Set-HudMetricLabel $ResetLabel $Parts.ResetValue $Parts.TextColor 52
2155
+ Set-HudMetricLabel $ResetLabel $Parts.ResetValue $Parts.TextColor $ResetWidth
1861
2156
  Set-HudDivider $Divider2 $Parts.WeekValue
1862
- Set-HudMetricLabel $WeekLabel $Parts.WeekValue $Parts.TextColor 52
2157
+ Set-HudMetricLabel $WeekLabel $Parts.WeekValue $Parts.TextColor $WeekWidth
1863
2158
  Set-HudMetricLabel $ExtraLabel $Parts.ExtraText $Parts.TextColor
1864
2159
  }
1865
2160
 
@@ -1906,8 +2201,8 @@ function Resize-HudToContent {
1906
2201
  $contentWidth = [math]::Max($codexWidth, $claudeWidth)
1907
2202
  $desiredWidth = $panel.Padding.Left + $panel.Padding.Right +
1908
2203
  $contentWidth +
1909
- 1
1910
- $desiredWidth = [math]::Max(150, [int][math]::Ceiling($desiredWidth))
2204
+ (Scale-HudValue 1)
2205
+ $desiredWidth = [math]::Max((Scale-HudValue 150), [int][math]::Ceiling($desiredWidth))
1911
2206
 
1912
2207
  $bothRows = $script:codexRowVisible -and $script:claudeRowVisible
1913
2208
  $desiredHeight = [int]$(if ($bothRows) { $script:hudTwoRowHeight } else { $script:hudOneRowHeight })
@@ -1935,8 +2230,8 @@ function Resize-HudToContent {
1935
2230
 
1936
2231
  function Show-HudMessage([string]$Message) {
1937
2232
  $codexPrefixLabel.Text = $Message
1938
- $codexPrefixLabel.ForeColor = [System.Drawing.Color]::FromArgb(145, 145, 145)
1939
- $codexPrefixLabel.Width = (Get-LabelTextWidth $codexPrefixLabel) + 1
2233
+ $codexPrefixLabel.ForeColor = Get-HudMutedTextColor
2234
+ $codexPrefixLabel.Width = (Get-LabelTextWidth $codexPrefixLabel) + (Scale-HudValue 1)
1940
2235
  $codexPrefixLabel.Visible = $true
1941
2236
  $codexPrefixLabel.Tag = $true
1942
2237
  foreach ($label in @($codexResetLabel, $codexWeekLabel, $codexExtraLabel, $claudePrefixLabel, $claudeResetLabel, $claudeWeekLabel, $claudeExtraLabel)) {
@@ -1974,16 +2269,28 @@ function Update-HudFromSnapshot($Snapshot) {
1974
2269
  $texts = ConvertTo-HudTexts $Snapshot
1975
2270
  $script:codexRowVisible = [bool]$texts.CodexVisible
1976
2271
  $script:claudeRowVisible = [bool]$texts.ClaudeVisible
2272
+ $resetValues = @()
2273
+ $weekValues = @()
2274
+ if ($texts.CodexVisible) {
2275
+ if ($texts.Codex.ResetValue) { $resetValues += $texts.Codex.ResetValue }
2276
+ if ($texts.Codex.WeekValue) { $weekValues += $texts.Codex.WeekValue }
2277
+ }
2278
+ if ($texts.ClaudeVisible) {
2279
+ if ($texts.Claude.ResetValue) { $resetValues += $texts.Claude.ResetValue }
2280
+ if ($texts.Claude.WeekValue) { $weekValues += $texts.Claude.WeekValue }
2281
+ }
2282
+ $resetWidth = Get-SharedHudColumnWidth $resetValues
2283
+ $weekWidth = Get-SharedHudColumnWidth $weekValues
1977
2284
  if ($texts.CodexVisible) {
1978
2285
  $codexRow.Visible = $true
1979
- Set-HudParts $texts.Codex $codexPrefixLabel $codexIconLabel $codexDivider1 $codexResetLabel $codexDivider2 $codexWeekLabel $codexExtraLabel
2286
+ Set-HudParts $texts.Codex $codexPrefixLabel $codexIconLabel $codexDivider1 $codexResetLabel $codexDivider2 $codexWeekLabel $codexExtraLabel $resetWidth $weekWidth
1980
2287
  } else {
1981
2288
  $codexRow.Visible = $false
1982
2289
  Set-HudControlsVisible $codexHudControls $false
1983
2290
  }
1984
2291
  if ($texts.ClaudeVisible) {
1985
2292
  $claudeRow.Visible = $true
1986
- Set-HudParts $texts.Claude $claudePrefixLabel $claudeIconLabel $claudeDivider1 $claudeResetLabel $claudeDivider2 $claudeWeekLabel $claudeExtraLabel
2293
+ Set-HudParts $texts.Claude $claudePrefixLabel $claudeIconLabel $claudeDivider1 $claudeResetLabel $claudeDivider2 $claudeWeekLabel $claudeExtraLabel $resetWidth $weekWidth
1987
2294
  } else {
1988
2295
  $claudeRow.Visible = $false
1989
2296
  Set-HudControlsVisible $claudeHudControls $false
@@ -2035,6 +2342,9 @@ $timer.add_Tick({ Invoke-HudPump })
2035
2342
  $topMostTimer = New-Object System.Windows.Forms.Timer
2036
2343
  $topMostTimer.Interval = 150
2037
2344
  $topMostTimer.add_Tick({ Update-HudVisibilityForFullscreen })
2345
+ $menuAutoHideTimer = New-Object System.Windows.Forms.Timer
2346
+ $menuAutoHideTimer.Interval = 50
2347
+ $menuAutoHideTimer.add_Tick({ Update-HudMenuAutoHide })
2038
2348
  $form.add_FormClosed({
2039
2349
  if ($canMove) {
2040
2350
  Write-HudPosition $form.Location
@@ -2043,6 +2353,8 @@ $form.add_FormClosed({
2043
2353
  $timer.Dispose()
2044
2354
  $topMostTimer.Stop()
2045
2355
  $topMostTimer.Dispose()
2356
+ $menuAutoHideTimer.Stop()
2357
+ $menuAutoHideTimer.Dispose()
2046
2358
  Stop-FullscreenEventHooks
2047
2359
  Stop-SnapshotFetch
2048
2360
  foreach ($box in @($codexIconLabel, $claudeIconLabel)) {
@@ -2051,6 +2363,9 @@ $form.add_FormClosed({
2051
2363
  $box.Image = $null
2052
2364
  }
2053
2365
  }
2366
+ if ($menu -and -not $menu.IsDisposed) {
2367
+ $menu.Dispose()
2368
+ }
2054
2369
  $font.Dispose()
2055
2370
  $symbolFont.Dispose()
2056
2371
  if ($hitForm -and -not $hitForm.IsDisposed) {
@@ -2094,4 +2409,5 @@ if ($ClickThrough) {
2094
2409
  $timer.Start()
2095
2410
  Start-FullscreenEventHooks
2096
2411
  $topMostTimer.Start()
2412
+ $menuAutoHideTimer.Start()
2097
2413
  [System.Windows.Forms.Application]::Run($form)