| Crates.io | jolt-platform |
| lib.rs | jolt-platform |
| version | 1.1.2 |
| created_at | 2026-01-11 20:02:59.879241+00 |
| updated_at | 2026-01-23 19:17:56.464635+00 |
| description | Cross-platform battery and power monitoring for jolt |
| homepage | |
| repository | https://github.com/jordond/jolt |
| max_upload_size | |
| id | 2036336 |
| size | 78,712 |
Cross-platform battery and power monitoring library for jolt.
This crate provides platform-agnostic traits (BatteryProvider, PowerProvider) with platform-specific implementations for macOS and Linux. It abstracts away the differences in how each OS exposes battery and power metrics.
| Platform | Battery | Power | Feature Flag |
|---|---|---|---|
| macOS | ✅ | ✅ | macos |
| Linux | ✅ | ✅ | linux |
| Windows | ❌ | ❌ | - |
| Metric | macOS | Linux | Notes |
|---|---|---|---|
| Charge percent | ✅ | ✅ | |
| Charge state | ✅ | ✅ | Charging, Discharging, Full, NotCharging, Unknown |
| Max capacity (Wh) | ✅ | ✅ | Current full charge capacity |
| Design capacity (Wh) | ✅ | ✅ | Original factory capacity |
| Health percent | ✅ | ✅ | max/design × 100 |
| Cycle count | ✅ | ✅ | May be None on some hardware |
| Voltage (mV) | ✅ | ✅ | |
| Amperage (mA) | ✅ | ✅ | Negative when discharging |
| Temperature (°C) | ✅ | ✅ | May be None on some hardware |
| Time to full | ✅ | ✅ | Estimated by OS/battery crate |
| Time to empty | ✅ | ✅ | Estimated by OS/battery crate |
| External connected | ✅ | ✅ | AC adapter detection |
| Charger wattage | ✅ | ❌ | macOS only (e.g., 96W) |
| Daily min/max SoC | ✅ | ❌ | macOS only (battery health tracking) |
| Metric | macOS | Linux | Notes |
|---|---|---|---|
| CPU power (W) | ✅ | ✅ | |
| GPU power (W) | ✅ | ✅ | |
| System power (W) | ✅ | ✅ | |
| Power mode | ✅ | ❌ | Low Power, Automatic, High Performance |
| ANE power (W) | ✅ | ❌ | Apple Neural Engine (internal only) |
| Data | Source | Notes |
|---|---|---|
| Battery basics | battery crate |
Cross-platform Rust crate |
| Battery extras | ioreg -rn AppleSmartBattery |
Charger watts, daily SoC, amperage |
| CPU/GPU power | IOReport framework | "Energy Model" channel group |
| System power | SMC (PSTR key) |
Total system power from SMC |
| Power mode | pmset -g |
lowpowermode/highpowermode flags |
| Data | Source | Notes |
|---|---|---|
| Battery basics | battery crate |
Cross-platform Rust crate |
| Battery extras | /sys/class/power_supply/BAT*/ |
Status, current_now |
| AC detection | /sys/class/power_supply/{AC,ADP}*/online |
|
| CPU power | RAPL (/sys/class/powercap/intel-rapl/) |
Requires permissions |
| GPU power | hwmon (/sys/class/hwmon/*/power1_input) |
amdgpu, i915, nouveau |
| Power mode | ❌ | Not implemented |
macOS: Uses ioreg to detect the NotCharging state (plugged in but not charging, e.g., charge limit reached). This is common on modern MacBooks with battery health features.
Linux: Reads /sys/class/power_supply/BAT*/status directly. The kernel reports "Not charging" when the battery is full or a charge limit is active.
macOS (Apple Silicon):
macOS (Intel):
Linux (RAPL):
/sys/class/powercap/macOS: Included in IOReport "Energy Model" - covers integrated and discrete GPUs on Apple Silicon.
Linux: Reads from hwmon interface. Supported drivers:
amdgpu - AMD GPUsi915 - Intel integrated graphicsnouveau - NVIDIA (open source driver)macOS: Reads current mode from pmset:
LowPower - Battery saver enabledAutomatic - Default balanced modeHighPerformance - Maximum performanceLinux: Currently returns Unknown. Power profiles could be read from:
power-profiles-daemon (GNOME)/sys/firmware/acpi/platform_profile (kernel 5.18+)No special permissions required. All APIs are accessible to normal users.
Battery: World-readable, no special permissions needed.
Power (RAPL): Requires read access to /sys/class/powercap/intel-rapl/*/energy_uj. Options:
power groupSee Linux Setup Guide for detailed instructions.
use jolt_platform::{BatteryProvider, PowerProvider};
#[cfg(target_os = "macos")]
use jolt_platform::macos::{MacOSBattery, MacOSPower};
#[cfg(target_os = "linux")]
use jolt_platform::linux::{LinuxBattery, LinuxPower};
fn main() -> color_eyre::Result<()> {
#[cfg(target_os = "macos")]
let mut battery = MacOSBattery::new()?;
#[cfg(target_os = "linux")]
let mut battery = LinuxBattery::new()?;
battery.refresh()?;
let info = battery.info();
println!("Charge: {:.1}%", info.charge_percent);
println!("State: {}", info.state);
println!("Health: {:.1}%", info.health_percent);
Ok(())
}
jolt-platform/
├── src/
│ ├── lib.rs # Public API, feature gates
│ ├── battery.rs # BatteryInfo struct, BatteryProvider trait
│ ├── power.rs # PowerInfo struct, PowerProvider trait
│ ├── types.rs # ChargeState, PowerMode enums
│ ├── macos/
│ │ ├── mod.rs
│ │ ├── battery.rs # MacOSBattery (battery crate + ioreg)
│ │ └── power.rs # MacOSPower (IOReport + SMC)
│ └── linux/
│ ├── mod.rs
│ ├── battery.rs # LinuxBattery (battery crate + sysfs)
│ └── power.rs # LinuxPower (RAPL + hwmon)
| Dependency | Used For | Platforms |
|---|---|---|
battery |
Cross-platform battery basics | All |
color-eyre |
Error handling | All |
sysinfo |
CPU usage fallback | All |
core-foundation |
macOS API bindings | macOS |
core-foundation-sys |
macOS FFI types | macOS |
libc |
System calls | All |