| 1 |
use crate::{Error, proxy::Proxy}; |
| 2 |
|
| 3 |
/// The interface provides information about the user-selected system-wide power |
| 4 |
/// profile, to sandboxed applications. |
| 5 |
/// |
| 6 |
/// It is not a portal in the strict sense, |
| 7 |
/// since it does not involve user interaction. |
| 8 |
/// |
| 9 |
/// Applications are expected to use this interface indirectly, via a library |
| 10 |
/// API such as the GLib [`gio::PowerProfileMonitor`](https://gtk-rs.org/gtk-rs-core/stable/latest/docs/gio/struct.PowerProfileMonitor.html) interface. |
| 11 |
/// |
| 12 |
/// Wrapper of the DBus interface: [`org.freedesktop.portal.PowerProfileMonitor`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.PowerProfileMonitor.html). |
| 13 |
#[derive(Debug)] |
| 14 |
#[doc(alias = "org.freedesktop.portal.PowerProfileMonitor")] |
| 15 |
pub struct PowerProfileMonitor(Proxy<'static>); |
| 16 |
|
| 17 |
impl PowerProfileMonitor { |
| 18 |
/// Create a new instance of [`PowerProfileMonitor`]. |
| 19 |
pub async fn new() -> Result<Self, Error> { |
| 20 |
let proxy = Proxy::new_desktop("org.freedesktop.portal.PowerProfileMonitor").await?; |
| 21 |
Ok(Self(proxy)) |
| 22 |
} |
| 23 |
|
| 24 |
/// Create a new instance of [`PowerProfileMonitor`]. |
| 25 |
pub async fn with_connection(connection: zbus::Connection) -> Result<Self, Error> { |
| 26 |
let proxy = Proxy::new_desktop_with_connection( |
| 27 |
connection, |
| 28 |
"org.freedesktop.portal.PowerProfileMonitor", |
| 29 |
) |
| 30 |
.await?; |
| 31 |
Ok(Self(proxy)) |
| 32 |
} |
| 33 |
|
| 34 |
/// Returns the version of the portal interface. |
| 35 |
pub fn version(&self) -> u32 { |
| 36 |
self.0.version() |
| 37 |
} |
| 38 |
|
| 39 |
/// Whether the power saver is enabled. |
| 40 |
/// |
| 41 |
/// # Specifications |
| 42 |
/// |
| 43 |
/// See also [`power-saver-enabled`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.PowerProfileMonitor.html#org-freedesktop-portal-powerprofilemonitor-power-saver-enabled) |
| 44 |
#[doc(alias = "power-saver-enabled")] |
| 45 |
pub async fn is_enabled(&self) -> Result<bool, Error> { |
| 46 |
self.0.property("power-saver-enabled").await |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
impl std::ops::Deref for PowerProfileMonitor { |
| 51 |
type Target = zbus::Proxy<'static>; |
| 52 |
|
| 53 |
fn deref(&self) -> &Self::Target { |
| 54 |
&self.0 |
| 55 |
} |
| 56 |
} |