Skip to content

Commit

Permalink
Update battery-health extension
Browse files Browse the repository at this point in the history
- Add publish script
- Add fallback if no capacity value is available
- Add maximum capacity value (#2)

Co-authored-by: Jatin Kumar <main.jatink@gmail.com>
  • Loading branch information
o1y and jatindotdev committed Dec 24, 2024
1 parent 075164f commit ea7341f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
5 changes: 4 additions & 1 deletion extensions/battery-health/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Battery Health Check Changelog

## [Add Battery Health Check] - 2022-07-05
## [Add Maximum Capacity Value] - {PR_MERGE_DATE}
- Added a new component to display the maximum capacity value of the battery.

## [Add Battery Health Check] - 2022-06-25

Initial version code
3 changes: 2 additions & 1 deletion extensions/battery-health/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"build": "ray build -e dist",
"dev": "ray develop",
"fix-lint": "ray lint --fix",
"lint": "ray lint"
"lint": "ray lint",
"publish": "npx @raycast/api@latest publish"
}
}
9 changes: 9 additions & 0 deletions extensions/battery-health/src/components/MaxCapacityItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import StatsListItem from "./StatsListItem";

const MaxCapacityItem = (props: { health: number }) => {
const health = props.health ? `${props.health}` : "--";

return <StatsListItem label="Maximum Capacity" value={health} />;
};

export default MaxCapacityItem;
20 changes: 19 additions & 1 deletion extensions/battery-health/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,37 @@ import TemperatureItem from "./components/TemperatureItem";
import ChargeItem from "./components/ChargeItem";
import PowerSourceItem from "./components/PowerSourceItem";
import ConditionItem from "./components/ConditionItem";
import MaxCapacityItem from "./components/MaxCapacityItem";

type State = {
batteryRegistry: any;

Check warning on line 16 in extensions/battery-health/src/index.tsx

View workflow job for this annotation

GitHub Actions / Check

Unexpected any. Specify a different type
batteryInfo: any;

Check warning on line 17 in extensions/battery-health/src/index.tsx

View workflow job for this annotation

GitHub Actions / Check

Unexpected any. Specify a different type
isLoading: boolean;
};

export default function Command() {
const [state, setState] = useState<State>({
batteryRegistry: {},
batteryInfo: {},
isLoading: true,
});

useEffect(() => {
(async () => {
try {
const { stdout } = await execa("/usr/sbin/ioreg", ["-arn", "AppleSmartBattery"]);
const { stdout: battery } = await execa("/usr/sbin/system_profiler", ["SPPowerDataType", "-xml"]);
const ioreg: any = plist.parse(stdout);

Check warning on line 33 in extensions/battery-health/src/index.tsx

View workflow job for this annotation

GitHub Actions / Check

Unexpected any. Specify a different type
const sysProfiler: any = plist.parse(battery);

Check warning on line 34 in extensions/battery-health/src/index.tsx

View workflow job for this annotation

GitHub Actions / Check

Unexpected any. Specify a different type
const batteryRegistry = ioreg[0];
const batteryInfo = sysProfiler[0];

setState((previous) => ({ ...previous, batteryRegistry: batteryRegistry, isLoading: false }));
setState((previous) => ({
...previous,
batteryRegistry: batteryRegistry,
batteryInfo: batteryInfo,
isLoading: false,
}));
} catch (e) {
setState((previous) => ({ ...previous, isLoading: false }));
}
Expand All @@ -51,6 +62,13 @@ export default function Command() {
maxCapacity={state.batteryRegistry["AppleRawMaxCapacity"] || state.batteryRegistry["MaxCapacity"]}
/>
<CycleCountItem cycles={state.batteryRegistry["CycleCount"]} />
<MaxCapacityItem
health={
state.batteryInfo["_items"]?.[0]?.["sppower_battery_health_info"]?.[
"sppower_battery_health_maximum_capacity"
]
}
/>
<PowerSourceItem
externalConnected={state.batteryRegistry["ExternalConnected"]}
adapter={state.batteryRegistry["AdapterDetails"]}
Expand Down

0 comments on commit ea7341f

Please sign in to comment.