Repository navigation
feat: show the battery's charge, power and health in its icon, with the percentage in a tooltip - #238
Merged
Merged
Conversation
…he percentage in a tooltip The battery widget draws a battery like the macOS menu bar's: its fill follows the charge and turns red at 10 % or less on battery power, a bolt shows it charging and a plug shows the Mac on its adapter without charging. An orange badge marks a battery macOS recommends servicing. The percentage moves to the tooltip, with the time left or until full. A new `battery` layout block draws it, so custom layouts, the Display choices and popups can use it. The provider adds `fields.health` and a `tooltip`, and its `icon` follows the charge in quarters. Health comes from `BatteryHealthCondition`, or a `BatteryHealth` of Poor: `BatteryHealth` can read "Check Battery" while System Settings shows the condition as Normal. Fixes #237
|
🎉 This PR is included in version 0.6.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The battery widget always draws a full battery, with a bolt while charging, next to its percentage. It can't show how full the battery is, that the Mac is on its adapter without charging, or that macOS recommends servicing the battery. Fixes #237.
Changes
The battery.
BatteryGlyph.swiftdraws a battery like the macOS menu bar's, sized byiconSizeand drawn in the text color:A new
batterylayout block draws it ({"type":"battery"}, with an optionalsource), so custom layouts, the Display choices and popups can use it. The block is added to the schema's block types.The provider.
PowerMonitor.output(battery:)turns IOKit's description into the output, which makes it testable. It adds:tooltip:62%, 3:20 left,45%, charging, full in 1:05,80%, plugged in, not chargingor100%, charged, withService recommendedon a second line when it applies;fields.health(normalorservice);iconthat follows the charge in quarters.Battery health. Health is
servicewhenBatteryHealthConditionis set, or whenBatteryHealthisPoor. On the MacBook this was built on,BatteryHealthreadsCheck Batterywhile System Settings shows Condition Normal and 83 %, so that key alone would warn wrongly. System Settings' capacity figure comes from a private call that returnskIOReturnNotPrivileged.Default layout and Display. A battery widget without a
layoutdraws only the battery. A Mac without a battery still shows the plug and AC. Icon only is battery's first Display choice and maps to the default, and every battery choice uses the battery block as its icon. A Display layout saved earlier, with asymbolicon, shows as Custom layout.Samples.
commandprovider, so CI redraws them with the new default.Docs.
popups.mddocuments the block.providers.mddocuments the new fields.create-a-widget.mdcovers the default look and the Display choices.themes.mdupdates the theme card sample.Surfaces:
Testing
swift teston this branch: 276 XCTest and 404 Swift Testing tests pass.BatteryTestscover:Check Batteryreading with an empty condition;BarViewrenders offscreen in five looks, light and dark, over dark and light backdrops:maindoesn't compile locally becauseBarView.bodytakes too long to type-check. CI's Xcode builds it. I ran these tests with that fix applied; it is in its own PR.Before/after screenshots follow in a comment.
Merging
A merge commit or rebase merge, so the
featcommit reaches the changelog.Claude Opus 5.5 via Claude Code