Created
July 24, 2026 16:00
-
-
Save v1993/d8fdf4a9b881b647000c2e5548222536 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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