https://github.com/pop-os/upower-dbus
Migrated to https://github.com/pop-os/dbus-settings-bindings
https://github.com/pop-os/upower-dbus
Last synced: about 2 months ago
JSON representation
Migrated to https://github.com/pop-os/dbus-settings-bindings
- Host: GitHub
- URL: https://github.com/pop-os/upower-dbus
- Owner: pop-os
- License: mpl-2.0
- Archived: true
- Created: 2022-01-05T19:20:31.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-09T19:53:00.000Z (over 2 years ago)
- Last Synced: 2024-10-29T18:08:13.959Z (6 months ago)
- Language: Rust
- Homepage:
- Size: 20.5 KB
- Stars: 6
- Watchers: 15
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- stars - pop-os/upower-dbus - Migrated to https://github.com/pop-os/dbus-settings-bindings (Rust)
README
# upower-dbus
A Rust library which interfaces with UPower status information through dbus.
## Examples
### Detecting if the system is running on battery
```rust,no_run
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
```rust,no_run
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(())
})
}```