feat: add upower-dbus for org.freedesktop.UPower
This commit is contained in:
parent
943c2a8bf2
commit
4d8815361d
10 changed files with 677 additions and 1 deletions
26
upower/examples/device.rs
Normal file
26
upower/examples/device.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2021 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
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!("BatteryLevel: {:?}", device.battery_level().await);
|
||||
println!("IconName: {:?}", device.icon_name().await);
|
||||
println!("IsPresent: {:?}", device.is_present().await);
|
||||
println!("Online: {:?}", device.online().await);
|
||||
println!("Percentage: {:?}", device.percentage().await);
|
||||
println!("State: {:?}", device.state().await);
|
||||
println!("Type: {:?}", device.type_().await);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
25
upower/examples/on_battery.rs
Normal file
25
upower/examples/on_battery.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright 2021 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
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 {
|
||||
eprintln!("{:?}", event.get().await);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue