Skip to content

[CmdPal][PerfMon] Add battery widget (charge, status, time remaining) - #47870

Merged
Mike Griese (zadjii-msft) merged 4 commits into
microsoft:mainfrom
Knyrps:feat/cmdpal-dock-battery-47218
May 18, 2026
Merged

Mike Griese (zadjii-msft) merged 4 commits into
microsoft:mainfrom
Knyrps:feat/cmdpal-dock-battery-47218

Conversation

@Knyrps

@Knyrps Knyrps (Knyrps) commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a Battery widget to the CmdPal Performance Monitor dock, exposing live charge percentage, charging/AC status, and estimated time remaining. The dock-band icon updates each tick to reflect the current charge level and charging state, matching the existing CPU/RAM/GPU/Network widget pattern.

Closes #47218

Detail

  • New SystemBatteryUsageWidgetPage in PerformanceWidgetsPage.cs, mirroring the existing widget pattern.
  • Data source: GetSystemPowerStatus via CsWin32 (AOT-safe), wrapped in BatteryStats and surfaced through SystemData / DataManager on the shared 1 s timer.
  • Live dock-band icon: Icons.cs caches 23 IconInfo instances (BatteryIcons[0..10], BatteryChargingIcons[0..10], BatteryUnknownIcon); alloc-free BatteryGlyph() selects the glyph per tick. Codepoints 0xEBA0–0xEBB5 / 0xEC02 (Segoe Fluent Icons MobBattery family).
  • Adaptive card template SystemBatteryTemplate.json registered as <None Update … PreserveNewest>, consistent with the other PerfMon templates.
  • New Battery_* strings under Strings\en-US\Resources.resw.
  • Handles GetSystemPowerStatus sentinels: BatteryLifePercent == 255, BatteryLifeTime == 0xFFFFFFFF, BatteryFlag == 0xFF, 0x80 (no battery), 0x08 (charging).

Screenshots

image

When the battery is at 100%, the widget will always show the "full" icon (MobBatteryCharging10).
image
Otherwise and when on AC, it will show the "charging" variant of the icon:
image
The icon also always reflects the current charging state: It resolves to the correct glyph in both charging and discharging states, rounded to the nearest 10% (so 0%, 10%, … 100%).

How tested

  • MSBuild CommandPalette.slnf /p:Configuration=Release /p:Platform=x64 /m /restore — green, 0 errors, 0 warnings.
  • Launched dev Microsoft.CmdPal.UI.exe, opened PerfMon dock, confirmed Battery widget renders charge %, status, time remaining, and that the dock-band glyph matches the current charge level (verified on AC, on battery, and while charging).
@Knyrps

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@niels9001

Copy link
Copy Markdown
Collaborator

Knyrps (@Knyrps) would you mind adding a screenshot to the PR description?

@Knyrps

Knyrps (Knyrps) commented May 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Edit: Mention Niels Laute (@niels9001)

Sure:
When the battery is at 100%, the widget will always show the "full" icon (MobBatteryCharging10).
image
Otherwise and when on AC, it will show the "charging" variant of the icon:
image
Edit 2: Oh, and the widget:
image

The battery percentage is polled every second on the shared DataManager timer (the same 1 Hz tick that already drives the CPU, memory, network and GPU widgets), so the dock band icon and the widget body stay in sync without any extra threads or timers. Each tick calls GetSystemPowerStatus once via CsWin32, maps the result through Icons.BatteryGlyph(percent, isCharging, hasBattery) against the pre built 23 entry IconInfo cache, and assigns the resulting IconInfo to _batteryItem.Icon, so the only allocation per tick is the assignment itself.

IsCharging is taken straight from the BatteryFlag charging bit (0x08); the ACLineStatus value is surfaced separately as IsOnAcPower and is used only for the status text, not for icon selection. That keeps the icon honest: at 100% on AC the system reports "not actively charging" and you see the full icon; while the battery is being topped up you see the charging variant; on battery you see the plain discharge glyph at the matching level; and when the OS reports unknown / no battery (BatteryFlag == 0xFF or 0x80, or BatteryLifePercent == 255) the widget falls back to MobBatteryUnknown (\uEC02) instead of guessing.

Apologies for not being able to provide screenshots at lower charge levels, my battery is currently full ^^ but the icon resolves to the correct glyph in both charging and discharging states, rounded to the nearest 10% (so 0%, 10%, … 100%).

@niels9001 Niels Laute (niels9001) added CmdPal - Dock Issues related to the Command Palette Dock Product-Command Palette Refers to the Command Palette utility labels May 15, 2026

@zadjii-msft Mike Griese (zadjii-msft) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly the one comment, but I'm excited to see this merge

@zadjii-msft Mike Griese (zadjii-msft) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks!

@zadjii-msft
Mike Griese (zadjii-msft) enabled auto-merge (squash) May 18, 2026 15:59
@Knyrps

Copy link
Copy Markdown
Contributor Author

This is great, thanks!

pleasure

@Knyrps

Knyrps (Knyrps) commented May 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Michael Jolley (@michaeljolley) can you approve or dismiss this?

@zadjii-msft

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).
@zadjii-msft
Mike Griese (zadjii-msft) merged commit 95ef94d into microsoft:main May 18, 2026
11 checks passed
@Knyrps
Knyrps (Knyrps) deleted the feat/cmdpal-dock-battery-47218 branch May 18, 2026 17:14
Mike Griese (zadjii-msft) added a commit that referenced this pull request May 19, 2026
title.

Basically just exposes bands that have each perf metric as the only
item.

Built on top of #47870

Closes #46200
@TheGamer1445891

Copy link
Copy Markdown

any option to use new battery icon?

@BEASTSHRIRAM

Copy link
Copy Markdown

I want to use this icon how can i? Knyrps (@Knyrps)

@Knyrps

Copy link
Copy Markdown
Contributor Author

Release v0.100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CmdPal - Dock Issues related to the Command Palette Dock Product-Command Palette Refers to the Command Palette utility

7 participants