mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Forwarded error from ProfileProxy::profile_names instead of 'expecting' there. Handled error up in main by logging. Reorganized code in ctrl_fan_cpu to keep consistent code structure
This commit is contained in:
@@ -365,6 +365,7 @@ fn handle_profile(
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if !cmd.next
|
||||
&& !cmd.create
|
||||
&& !cmd.list
|
||||
&& cmd.curve.is_none()
|
||||
&& cmd.max_percentage.is_none()
|
||||
&& cmd.min_percentage.is_none()
|
||||
@@ -393,6 +394,9 @@ fn handle_profile(
|
||||
}
|
||||
if cmd.next {
|
||||
dbus.proxies().profile().next_fan()?;
|
||||
} else if cmd.list {
|
||||
let profile_names = dbus.proxies().profile().profile_names()?;
|
||||
println!("Available profiles are {}", profile_names);
|
||||
} else {
|
||||
dbus.proxies()
|
||||
.profile()
|
||||
|
||||
@@ -127,8 +127,28 @@ impl DbusFanAndCpu {
|
||||
"Failed".to_string()
|
||||
}
|
||||
|
||||
fn profile_names(&self) -> String {
|
||||
if let Ok(ctrl) = self.inner.try_lock() {
|
||||
if let Ok(mut cfg) = ctrl.config.try_lock() {
|
||||
cfg.read();
|
||||
|
||||
let profile_names: String = cfg
|
||||
.power_profiles
|
||||
.keys()
|
||||
.cloned()
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ");
|
||||
|
||||
return profile_names;
|
||||
}
|
||||
}
|
||||
|
||||
"Failed".to_string()
|
||||
}
|
||||
|
||||
#[dbus_interface(signal)]
|
||||
fn notify_profile(&self, profile: &str) -> zbus::Result<()> {}
|
||||
|
||||
}
|
||||
|
||||
impl crate::ZbusAdd for DbusFanAndCpu {
|
||||
|
||||
@@ -41,6 +41,9 @@ trait Daemon {
|
||||
/// Profiles method
|
||||
fn profiles(&self) -> zbus::Result<String>;
|
||||
|
||||
/// ProfileNames method
|
||||
fn profile_names(&self) -> zbus::Result<String>;
|
||||
|
||||
/// SetProfile method
|
||||
fn set_profile(&self, profile: &str) -> zbus::Result<()>;
|
||||
|
||||
@@ -82,6 +85,11 @@ impl<'a> ProfileProxy<'a> {
|
||||
self.0.set_profile(&serde_json::to_string(cmd).unwrap())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn profile_names(&self) -> Result<String> {
|
||||
self.0.profile_names()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn connect_notify_profile(
|
||||
&self,
|
||||
|
||||
@@ -80,6 +80,8 @@ pub struct ProfileCommand {
|
||||
pub next: bool,
|
||||
#[options(help = "create the profile if it doesn't exist")]
|
||||
pub create: bool,
|
||||
#[options(help = "list available profiles")]
|
||||
pub list: bool,
|
||||
|
||||
#[options(meta = "", help = "enable or disable cpu turbo")]
|
||||
pub turbo: Option<bool>,
|
||||
|
||||
Reference in New Issue
Block a user