@domicile-desktop/system-battery
v0.0.0-alpha-0b7f6878c1a8
Published
The battery for a Domicile shell: UPower's charge and charger state, over D-Bus.
Downloads
2,494
Readme
@domicile-desktop/system-battery
The battery for a Domicile shell, from UPower over the system bus.
- Reads UPower's DisplayDevice: the combined charge of every battery and whether a charger is connected.
- Built on
@domicile-desktop/sdk/system'sdbusCallanddbusMatch. See SHELL-SYSTEM-ACCESS.md. - Needs
upowerrunning. Without it, calls fail with aDbuserror.
Usage
import { system } from "@domicile-desktop/sdk/system";
import { watchBattery } from "@domicile-desktop/system-battery/battery";
const watched = await watchBattery(system(domicile));
watched.match({
Err: (error) => console.error(error.message),
Ok: async ({ items }) => {
for await (const battery of items) {
// `None()` without a battery; else `Some({ charge, charging })`.
}
},
});readBattery(system): the reading now,Result<Option<Battery>, SystemError>.watchBattery(system): the reading now as the first item, then one per UPower change.stop()ends it.chargeis 0 through 1.chargingis true unless the battery is draining (discharging, empty or pending discharge), so a full battery on AC counts.- Lock: both work while the desktop is locked, so a lock screen can show the battery (LOCK.md).
Dependencies
@domicile-desktop/sdkfor the system calls,zodto parse UPower's replies,@cprussin/option-resultforResultandOption.
Test
bun run turbo test --filter @domicile-desktop/system-batteryTests answer with recorded UPower replies through a fake System.
