Library for querying system battery information.
Find a file
Lilly Rose Berner 46193ea883
All checks were successful
/ build (push) Successful in 15s
/ compile-x86_64-unknown-linux-gnu (push) Successful in 50s
/ compile-aarch64-pc-windows-msvc (push) Successful in 36s
/ compile-x86_64-pc-windows-msvc (push) Successful in 36s
/ compile-x86_64-apple-darwin (push) Successful in 20s
/ lint (push) Successful in 32s
/ compile-aarch64-unknown-linux-gnu (push) Successful in 53s
/ compile-loongarch64-unknown-linux-gnu (push) Successful in 52s
/ compile-riscv64gc-unknown-linux-gnu (push) Successful in 53s
/ compile-aarch64-apple-darwin (push) Successful in 19s
Bump version to 2.1.0
Signed-off-by: Lilly Rose Berner <lilly@lostluma.net>
2026-05-25 21:58:36 +02:00
.cargo Configure default linkers for cross-compiling 2025-08-12 16:37:59 +02:00
.forgejo/workflows Update Gradle actions to 6.1.0 2026-05-15 20:04:59 +02:00
gradle Update Java dependencies 2026-05-15 20:08:50 +02:00
src/main Bump version to 2.1.0 2026-05-25 21:58:36 +02:00
.editorconfig Create and apply consistent formatting settings 2026-05-15 16:30:33 +02:00
.gitignore Add VS Code directory to gitignore 2024-10-20 14:49:21 +02:00
build.gradle.kts Create and apply consistent formatting settings 2026-05-15 16:30:33 +02:00
Cargo.lock Update jni crate to 0.22.4 2026-05-15 18:41:28 +02:00
Cargo.toml Bump backing library version to 2.1.0 2026-05-24 23:22:21 +02:00
gradle.properties Bump version to 2.1.0 2026-05-25 21:58:36 +02:00
gradlew Update Gradle to 9.5.1 2026-05-15 20:05:50 +02:00
gradlew.bat Update Gradle to 9.5.1 2026-05-15 20:05:50 +02:00
LICENSE Update license year 2026-01-01 17:32:49 +01:00
README.md Link to api package when referring to it for docs 2026-05-13 23:15:00 +02:00
rustfmt.toml Create and apply consistent formatting settings 2026-05-15 16:30:33 +02:00
settings.gradle.kts Create and apply consistent formatting settings 2026-05-15 16:30:33 +02:00

Battery

Library for querying system battery information.
A Java 8+ JNI wrapper for the starship battery crate.

Usage

To get started create a Manager instance and query it for information:

try (Manager manager = Manager.create()) {
    for (Battery battery : manager.batteries()) {
        // Query battery for its information here
        Optional<Duration> timeToEmpty = battery.timeToEmpty();
    }
}

For more detailed information consult the documentation attached to all types in the api package.

Installation

The library can be installed from the releases repository on maven.lostluma.net in two variants:

  • default: Downloads, validates, and caches the dynamic library on demand. Saves bandwidth and disk space.
  • bundled: Contains the dynamic library for all platforms. Recommended if first application startup may be offline.

Releases starting with version 2.0.0 are signed using PGP key 831BD989D1B19DBF15DB58A6D99A97B69E896870.


The dynamic library comes prebuilt for the following platforms:

aarch64 amd64 riscv64 loongarch64
Linux yes yes yes yes
MacOS yes yes
Windows yes yes

For running on other platforms see the Behavior Customization section below.

Behavior Customization

Some library behavior may be controlled using system properties or the Library utility class:

  • battery.natives.cache.dir: Use a different storage location for cached files
  • battery.natives.download: Controls automatic backing library download for the default variant
  • battery.natives.path: Provide your own build of the backing library for usage on more platforms

Values overwritten using system properties will take precedence over those set via the Library class.