wayle_power_profiles/lib.rs
1//! Power profile management via power-profiles-daemon D-Bus.
2//!
3//! # Quick Start
4//!
5//! ```rust,no_run
6//! use wayle_power_profiles::PowerProfilesService;
7//!
8//! # async fn example() -> Result<(), wayle_power_profiles::Error> {
9//! let service = PowerProfilesService::new().await?;
10//!
11//! // Check current profile
12//! let profile = service.power_profiles.active_profile.get();
13//! println!("Current profile: {profile}");
14//!
15//! // List available profiles
16//! for p in service.power_profiles.profiles.get() {
17//! println!(" {} (driver: {})", p.profile, p.driver);
18//! }
19//! # Ok(())
20//! # }
21//! ```
22//!
23//! # Watching for Changes
24//!
25//! ```rust,no_run
26//! use wayle_power_profiles::PowerProfilesService;
27//! use futures::StreamExt;
28//!
29//! # async fn example() -> Result<(), wayle_power_profiles::Error> {
30//! # let service = PowerProfilesService::new().await?;
31//! // React to profile changes
32//! let mut stream = service.power_profiles.active_profile.watch();
33//! while let Some(profile) = stream.next().await {
34//! println!("Profile changed to: {profile}");
35//! }
36//! # Ok(())
37//! # }
38//! ```
39//!
40//! # Profile Control
41//!
42//! ```rust,no_run
43//! use wayle_power_profiles::PowerProfilesService;
44//! use wayle_power_profiles::types::profile::{PowerProfile, PerformanceDegradationReason};
45//!
46//! # async fn example() -> Result<(), wayle_power_profiles::Error> {
47//! # let service = PowerProfilesService::new().await?;
48//! // Switch to performance mode
49//! service.power_profiles.set_active_profile(PowerProfile::Performance).await?;
50//!
51//! // Check if performance is degraded (e.g., thermal throttling)
52//! let degraded = service.power_profiles.performance_degraded.get();
53//! if degraded != PerformanceDegradationReason::None {
54//! println!("Performance degraded: {degraded}");
55//! }
56//! # Ok(())
57//! # }
58//! ```
59//!
60//! # Reactive Properties
61//!
62//! All fields are [`Property<T>`](wayle_core::Property):
63//! - `.get()` - Current value snapshot
64//! - `.watch()` - Stream yielding on changes
65//!
66//! # Service Fields
67//!
68//! | Field | Type | Description |
69//! |-------|------|-------------|
70//! | `active_profile` | [`PowerProfile`](types::profile::PowerProfile) | Currently active profile |
71//! | `performance_degraded` | [`PerformanceDegradationReason`](types::profile::PerformanceDegradationReason) | Why performance is degraded |
72//! | `profiles` | `Vec<Profile>` | Available profiles and their drivers |
73//! | `actions` | `Vec<String>` | Daemon-supported actions |
74//! | `active_profile_holds` | `Vec<ProfileHold>` | Applications holding a profile |
75//!
76//! # Configuration
77//!
78//! | Method | Effect |
79//! |--------|--------|
80//! | `with_daemon()` | Switch profiles from scripts or other processes |
81//!
82//! ```rust,no_run
83//! use wayle_power_profiles::PowerProfilesService;
84//!
85//! # async fn example() -> Result<(), wayle_power_profiles::Error> {
86//! let service = PowerProfilesService::builder()
87//! .with_daemon()
88//! .build()
89//! .await?;
90//! # Ok(())
91//! # }
92//! ```
93//!
94//! # D-Bus Interface
95//!
96//! When `with_daemon()` is enabled, the service registers on the session bus.
97//!
98//! - **Service:** `com.wayle.PowerProfiles1`
99//! - **Path:** `/com/wayle/PowerProfiles`
100//! - **Interface:** `com.wayle.PowerProfiles1`
101//!
102//! See [`dbus.md`](https://github.com/wayle-rs/wayle/blob/master/crates/wayle-power-profiles/dbus.md) for the full interface specification.
103//!
104//! # Control Methods
105//!
106//! - [`set_active_profile()`](PowerProfiles::set_active_profile) - Switch power profile
107
108mod builder;
109mod error;
110mod proxy;
111mod service;
112
113/// Reactive power profile state.
114pub mod core;
115/// D-Bus interface for CLI control.
116pub mod dbus;
117/// Power profile type definitions.
118pub mod types;
119
120pub use core::PowerProfiles;
121
122pub use builder::PowerProfilesServiceBuilder;
123pub use error::Error;
124pub use service::PowerProfilesService;
125
126#[doc = include_str!("../README.md")]
127#[cfg(doctest)]
128pub struct ReadmeDocTests;