5 unstable releases

0.3.2 Jan 9, 2023
0.3.1 Dec 5, 2022
0.3.0 Oct 3, 2022
0.2.0 Jan 5, 2022
0.1.0 May 9, 2018

#3 in #logind

Download history 307/week @ 2024-03-14 1082/week @ 2024-03-21 544/week @ 2024-03-28 467/week @ 2024-04-04 542/week @ 2024-04-11 949/week @ 2024-04-18 1410/week @ 2024-04-25 1721/week @ 2024-05-02 1336/week @ 2024-05-09 1302/week @ 2024-05-16 775/week @ 2024-05-23 819/week @ 2024-05-30 689/week @ 2024-06-06 611/week @ 2024-06-13 567/week @ 2024-06-20 455/week @ 2024-06-27

2,442 downloads per month
Used in 3 crates

MIT license

15KB
118 lines

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(())
    })
}

Dependencies

~13–27MB
~387K SLoC