Skip to content

Battery

Library and CLI tool for monitoring upowerd devices.

Installation

  1. install dependencies
sh
sudo pacman -Syu meson vala json-glib gobject-introspection
sh
sudo dnf install meson gcc valac json-glib-devel gobject-introspection-devel
sh
sudo apt install meson valac libjson-glib-dev gobject-introspection

INFO

Although UPower is not a direct build dependency, it should be self-explanatory that the daemon is required to be available at runtime.

  1. clone repo
sh
git clone https://github.com/aylur/astal.git
cd astal/lib/battery
  1. install
sh
meson setup build
meson install -C build

TIP

Most distros recommend manual installs in /usr/local, which is what meson defaults to. If you want to install to /usr instead which most package managers do, set the prefix option:

sh
meson setup --prefix /usr build

Usage

You can browse the Battery reference.

CLI

sh
astal-battery --help

Library

js
import Battery from "gi://AstalBattery"

const battery = Battery.get_default()

print(battery.percentage)
py
from gi.repository import AstalBattery as Battery

battery = Battery.get_default()

print(battery.get_percentage())
lua
local Battery = require("lgi").require("AstalBattery")

local battery = Battery.get_default()

print(battery.percentage)
vala
// Not yet documented