Library for querying system battery information.
Find a file
Lilly Rose Berner f75489c055
All checks were successful
/ build (push) Successful in 12s
/ compile-x86_64-pc-windows-msvc (push) Successful in 36s
/ compile-aarch64-unknown-linux-gnu (push) Successful in 48s
/ compile-riscv64gc-unknown-linux-gnu (push) Successful in 44s
/ compile-aarch64-apple-darwin (push) Successful in 20s
/ compile-x86_64-apple-darwin (push) Successful in 20s
/ compile-x86_64-unknown-linux-gnu (push) Successful in 42s
/ compile-aarch64-pc-windows-msvc (push) Successful in 37s
/ compile-loongarch64-unknown-linux-gnu (push) Successful in 44s
/ lint (push) Successful in 23s
Bump version to 2.0.0
Signed-off-by: Lilly Rose Berner <lilly@lostluma.net>
2026-01-01 17:35:13 +01:00
.cargo Configure default linkers for cross-compiling 2025-08-12 16:37:59 +02:00
.forgejo/workflows Add CI concurrency configuration 2026-01-01 15:50:15 +01:00
gradle Switch to jspecify nullability annotations 2025-12-08 20:34:38 +01:00
src/main Bump version to 2.0.0 2026-01-01 17:35:13 +01:00
.gitignore Add VS Code directory to gitignore 2024-10-20 14:49:21 +02:00
build.gradle.kts Add meta information to maven pom 2025-12-17 16:02:18 +01:00
Cargo.lock Bump backing library version to 2.0.0 2025-12-25 12:45:52 +01:00
Cargo.toml Bump backing library version to 2.0.0 2025-12-25 12:45:52 +01:00
gradle.properties Bump version to 2.0.0 2026-01-01 17:35:13 +01:00
gradlew Update Gradle to 9.1.0 2025-10-01 16:01:03 +02:00
gradlew.bat Update Gradle to 9.1.0 2025-10-01 16:01:03 +02:00
LICENSE Update license year 2026-01-01 17:32:49 +01:00
README.md Fix table formatting 2026-01-01 15:46:59 +01:00
settings.gradle.kts Update foojay resolver plugin to 1.0.0 2025-12-04 21:40:42 +01: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.