upower_dbus

Crates.ioupower_dbus
lib.rsupower_dbus
version0.3.2
sourcesrc
created_at2018-05-09 15:35:22.562355
updated_at2023-01-09 19:53:29.069067
descriptionUPower info via zbus
homepage
repositoryhttps://github.com/pop-os/upower-dbus
max_upload_size
id64564
size51,033
Jeremy Soller (jackpot51)

documentation

README

upower-dbus

A Rust library which interfaces with UPower status information through dbus.

Examples

Detecting if the system is running on battery

extern crate upower_dbus;

use futures::stream::StreamExt;
use upower_dbus::UPowerProxy;

fn main() -> zbus::Result<()> {
    futures::executor::block_on(async move {
        let connection = zbus::Connection::system().await?;

        let upower = UPowerProxy::new(&connection).await?;

        println!("On Battery: {:?}", upower.on_battery().await);

        let mut stream = upower.receive_on_battery_changed().await;

        while let Some(event) = stream.next().await {
            println!("On Battery: {:?}", event.get().await);
        }

        Ok(())
    })
}

Getting the current battery status as a percentage

extern crate upower_dbus;

use upower_dbus::UPowerProxy;

fn main() -> zbus::Result<()> {
    futures::executor::block_on(async move {
        let connection = zbus::Connection::system().await?;

        let upower = UPowerProxy::new(&connection).await?;

        let device = upower.get_display_device().await?;

        println!("Battery: {:?}", device.percentage().await);

        Ok(())
    })
}

Commit count: 12

cargo fmt