ROGCC: better handling of fan curve profile

This commit is contained in:
Luke Jones
2025-03-03 20:19:56 +13:00
parent aee465aced
commit 3a900f23fe
2 changed files with 113 additions and 78 deletions

View File

@@ -9,6 +9,7 @@ pub enum Error {
ConfigLockFail, ConfigLockFail,
XdgVars, XdgVars,
Zbus(zbus::Error), Zbus(zbus::Error),
ZbusFdo(zbus::fdo::Error),
Notification(notify_rust::error::Error), Notification(notify_rust::error::Error),
} }
@@ -21,6 +22,7 @@ impl fmt::Display for Error {
Error::ConfigLockFail => write!(f, "Failed to lock user config"), Error::ConfigLockFail => write!(f, "Failed to lock user config"),
Error::XdgVars => write!(f, "XDG environment vars appear unset"), Error::XdgVars => write!(f, "XDG environment vars appear unset"),
Error::Zbus(err) => write!(f, "Error: {}", err), Error::Zbus(err) => write!(f, "Error: {}", err),
Error::ZbusFdo(err) => write!(f, "Error: {}", err),
Error::Notification(err) => write!(f, "Notification Error: {}", err), Error::Notification(err) => write!(f, "Notification Error: {}", err),
} }
} }
@@ -40,6 +42,12 @@ impl From<zbus::Error> for Error {
} }
} }
impl From<zbus::fdo::Error> for Error {
fn from(err: zbus::fdo::Error) -> Self {
Error::ZbusFdo(err)
}
}
impl From<notify_rust::error::Error> for Error { impl From<notify_rust::error::Error> for Error {
fn from(err: notify_rust::error::Error) -> Self { fn from(err: notify_rust::error::Error) -> Self {
Error::Notification(err) Error::Notification(err)

View File

@@ -1,7 +1,8 @@
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use log::{error, info}; use log::error;
use rog_dbus::zbus_fan_curves::FanCurvesProxy; use rog_dbus::zbus_fan_curves::FanCurvesProxy;
use rog_dbus::zbus_platform::PlatformProxy;
use rog_platform::platform::PlatformProfile; use rog_platform::platform::PlatformProfile;
use rog_profiles::fan_curve_set::CurveData; use rog_profiles::fan_curve_set::CurveData;
use slint::{ComponentHandle, Model, Weak}; use slint::{ComponentHandle, Model, Weak};
@@ -100,49 +101,75 @@ pub fn setup_fan_curve_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) {
tokio::spawn(async move { tokio::spawn(async move {
// Create the connections/proxies here to prevent future delays in process // Create the connections/proxies here to prevent future delays in process
let conn = if let Ok(conn) = zbus::Connection::system().await.map_err(|e| error!("{e:}")) { let conn = match zbus::Connection::system().await {
conn Ok(conn) => conn,
} else { Err(e) => {
error!("{e:}");
return; return;
}
}; };
let fans = if let Ok(fans) = FanCurvesProxy::new(&conn).await.map_err(|e| error!("{e:}")) {
fans let fans = match FanCurvesProxy::new(&conn).await {
} else { Ok(fans) => fans,
info!( Err(e) => {
"This device may not have an Fan Curve control. If not then the error can be \ error!("{e:}");
ignored"
);
return; return;
}
};
let platform = match PlatformProxy::new(&conn).await {
Ok(platform) => platform,
Err(e) => {
error!("{e:}");
return;
}
};
let platform_profile_choices = match platform.platform_profile_choices().await {
Ok(choices) => choices,
Err(e) => {
error!("{e:}");
return;
}
}; };
let handle_copy = handle.clone(); let handle_copy = handle.clone();
// Do initial setup // Do initial setup
let Ok(balanced) = fans let balanced = match fans.fan_curve_data(PlatformProfile::Balanced).await {
.fan_curve_data(PlatformProfile::Balanced) Ok(data) => data,
.await Err(e) => {
.map_err(|e| error!("Couldn't get balanced data: {e:}")) error!("Couldn't get balanced data: {e:}");
else {
return; return;
}
}; };
let Ok(perf) = fans
.fan_curve_data(PlatformProfile::Performance) let perf = match fans.fan_curve_data(PlatformProfile::Performance).await {
.await Ok(data) => data,
.map_err(|e| error!("Couldn't get performance data: {e:}")) Err(e) => {
else { error!("Couldn't get performance data: {e:}");
return; return;
}
}; };
let Ok(quiet) = fans
.fan_curve_data(PlatformProfile::Quiet) // TODO: the fan curve stuff was written donkeys ago with the expectation that
.await // only 3 profiles existed
.map_err(|e| error!("Couldn't get quiet data: {e:}")) let profile = if platform_profile_choices.contains(&PlatformProfile::Quiet) {
else { PlatformProfile::Quiet
} else {
PlatformProfile::Quiet
};
let quiet = match fans.fan_curve_data(profile).await {
Ok(data) => data,
Err(e) => {
error!("Couldn't get quiet data: {e:}");
return; return;
}
}; };
update_fan_data(handle, balanced, perf, quiet); update_fan_data(handle, balanced, perf, quiet);
let handle_next1 = handle_copy.clone(); let handle_next1 = handle_copy.clone();
handle_copy if let Err(e) = handle_copy.upgrade_in_event_loop(move |handle| {
.upgrade_in_event_loop(move |handle| {
let global = handle.global::<FanPageData>(); let global = handle.global::<FanPageData>();
let fans1 = fans.clone(); let fans1 = fans.clone();
global.on_set_profile_default(move |profile| { global.on_set_profile_default(move |profile| {
@@ -187,9 +214,9 @@ pub fn setup_fan_curve_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) {
.ok() .ok()
}); });
}); });
}) }) {
.map_err(|e| error!("setup_fan_curve_page: upgrade_in_event_loop: {e:?}")) error!("setup_fan_curve_page: upgrade_in_event_loop: {e:?}");
.ok(); }
}); });
} }