Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Update Extension] System Monitor - Fix battery level #16020

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/system-monitor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# System Monitor Changelog

## [Fix] - 2025-01-02

- Fix issue when showing battery level on Intel-based Macs

## [Chore] - 2024-11-24

- Fixed wording in description
Expand Down
34 changes: 20 additions & 14 deletions extensions/system-monitor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions extensions/system-monitor/src/Power/PowerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { convertMsToTime, execp } from "../utils";
export const getBatteryData = async (): Promise<BatteryDataInterface> => {
const smartBatteryOutput = await execp("/usr/sbin/ioreg -arn AppleSmartBattery");
const systemProfilerOutput = await execp(
`/usr/sbin/system_profiler SPPowerDataType | grep -e 'Condition' -e 'Maximum Capacity'| awk '{print $NF}'`,
`/usr/sbin/system_profiler SPPowerDataType | /usr/bin/grep -e 'Condition' -e 'Maximum Capacity'| /usr/bin/awk '{print $NF}'`,
);
const smartBattery = (plist.parse(smartBatteryOutput) as PlistArray)[0] as PlistObject;
const [condition, maximumCapacity] = systemProfilerOutput.split("\n");
const batteryLevel = await execp("/usr/bin/pmset -g batt | /usr/bin/grep -Eo '\\d+%' | /usr/bin/tr -d '%'");

return {
batteryLevel: smartBattery.CurrentCapacity.toString(),
batteryLevel,
condition,
cycleCount: smartBattery.CycleCount.toString(),
fullyCharged: !!smartBattery.FullyCharged,
Expand Down