Add profile configuration functions

This commit is contained in:
Lucy 2022-02-15 10:42:49 -05:00
parent e03225384b
commit b8d17f2b2f
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
2 changed files with 28 additions and 0 deletions

View file

@ -4,6 +4,8 @@
extern crate relm4_macros;
pub mod dbus;
pub mod profile;
use gtk4::{gio::ApplicationFlags, prelude::*, Orientation};
use once_cell::sync::Lazy;
use tokio::runtime::Runtime;

View file

@ -0,0 +1,26 @@
use crate::dbus::PowerDaemonProxy;
use zbus::Result;
pub enum Profile {
Performance,
Balanced,
Battery,
}
pub async fn get_current_profile(daemon: &PowerDaemonProxy<'_>) -> Result<Profile> {
let profile = daemon.get_profile().await?;
match profile.as_str() {
"Performance" => Ok(Profile::Performance),
"Balanced" => Ok(Profile::Balanced),
"Battery" => Ok(Profile::Battery),
_ => panic!("Unknown profile: {}", profile),
}
}
pub async fn set_profile(daemon: &PowerDaemonProxy<'_>, profile: Profile) -> zbus::Result<()> {
match profile {
Profile::Performance => daemon.performance().await,
Profile::Balanced => daemon.balanced().await,
Profile::Battery => daemon.battery().await,
}
}