From 0a2b2ed543678d9f827fc181b538d6b3f6975fc0 Mon Sep 17 00:00:00 2001 From: Oliver Mesieh Date: Tue, 24 Dec 2024 23:05:18 +0100 Subject: [PATCH] Update battery-health extension - Add publish script - Add fallback if no capacity value is available - Add maximum capacity value (#2) --- extensions/battery-health/CHANGELOG.md | 5 ++++- extensions/battery-health/package.json | 3 ++- .../src/components/MaxCapacityItem.tsx | 9 +++++++++ extensions/battery-health/src/index.tsx | 20 ++++++++++++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 extensions/battery-health/src/components/MaxCapacityItem.tsx diff --git a/extensions/battery-health/CHANGELOG.md b/extensions/battery-health/CHANGELOG.md index 9dab1d50668..2f5faa5943d 100644 --- a/extensions/battery-health/CHANGELOG.md +++ b/extensions/battery-health/CHANGELOG.md @@ -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 diff --git a/extensions/battery-health/package.json b/extensions/battery-health/package.json index 2b11a688179..8171ef34562 100644 --- a/extensions/battery-health/package.json +++ b/extensions/battery-health/package.json @@ -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" } } diff --git a/extensions/battery-health/src/components/MaxCapacityItem.tsx b/extensions/battery-health/src/components/MaxCapacityItem.tsx new file mode 100644 index 00000000000..43e72812827 --- /dev/null +++ b/extensions/battery-health/src/components/MaxCapacityItem.tsx @@ -0,0 +1,9 @@ +import StatsListItem from "./StatsListItem"; + +const MaxCapacityItem = (props: { health: number }) => { + const health = props.health ? `${props.health}` : "--"; + + return ; +}; + +export default MaxCapacityItem; diff --git a/extensions/battery-health/src/index.tsx b/extensions/battery-health/src/index.tsx index 3b8c382aa4f..03c413fe911 100644 --- a/extensions/battery-health/src/index.tsx +++ b/extensions/battery-health/src/index.tsx @@ -10,15 +10,18 @@ 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; + batteryInfo: any; isLoading: boolean; }; export default function Command() { const [state, setState] = useState({ batteryRegistry: {}, + batteryInfo: {}, isLoading: true, }); @@ -26,10 +29,18 @@ export default function Command() { (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); + const sysProfiler: any = plist.parse(battery); 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 })); } @@ -51,6 +62,13 @@ export default function Command() { maxCapacity={state.batteryRegistry["AppleRawMaxCapacity"] || state.batteryRegistry["MaxCapacity"]} /> +