Skip to content

Instantly share code, notes, and snippets.

@v1993
Created July 24, 2026 16:00
Show Gist options
  • Select an option

  • Save v1993/d8fdf4a9b881b647000c2e5548222536 to your computer and use it in GitHub Desktop.

Select an option

Save v1993/d8fdf4a9b881b647000c2e5548222536 to your computer and use it in GitHub Desktop.
use futures_lite::stream::StreamExt;
use zbus::names::InterfaceName;
use zbus::zvariant::Str;
use zbus::zvariant::Value;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
const INTERFACE_NAME: InterfaceName =
InterfaceName::from_static_str_unchecked("org.freedesktop.UPower.PowerProfiles");
const PROPERTY_NAME: &str = "ActiveProfile";
let connection = zbus::Connection::system().await?;
let properties_proxy = zbus::fdo::PropertiesProxy::builder(&connection)
.destination("org.freedesktop.UPower.PowerProfiles")?
.path("/org/freedesktop/UPower/PowerProfiles")?
.build()
.await?;
let mut changes_stream = properties_proxy
.receive_properties_changed_with_args(&[(0, INTERFACE_NAME.as_str())])
.await?;
let power_profile: Str = properties_proxy
.get(INTERFACE_NAME, PROPERTY_NAME)
.await?
.try_into()?;
println!("Started with power profile {power_profile}");
while let Some(change) = changes_stream.next().await {
let args = change.args()?;
if let Some(Value::Str(power_profile)) = args.changed_properties().get("ActiveProfile") {
println!("Switched to power profile {power_profile}");
}
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment