mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Better everything
This commit is contained in:
@@ -6,12 +6,12 @@ pub mod setup_system;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use config_traits::StdConfig;
|
||||
use rog_dbus::zbus_platform::PlatformProxyBlocking;
|
||||
use rog_dbus::has_iface_blocking;
|
||||
use slint::{ComponentHandle, PhysicalSize, SharedString, Weak};
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::ui::setup_anime::setup_anime_page;
|
||||
use crate::ui::setup_aura::{has_aura_iface_blocking, setup_aura_page};
|
||||
use crate::ui::setup_aura::setup_aura_page;
|
||||
use crate::ui::setup_fans::setup_fan_curve_page;
|
||||
use crate::ui::setup_system::{setup_system_page, setup_system_page_callbacks};
|
||||
use crate::{AppSettingsPageData, MainWindow};
|
||||
@@ -108,19 +108,13 @@ pub fn setup_window(config: Arc<Mutex<Config>>) -> MainWindow {
|
||||
}
|
||||
};
|
||||
|
||||
let conn = zbus::blocking::Connection::system().unwrap();
|
||||
let platform = PlatformProxyBlocking::new(&conn).unwrap();
|
||||
|
||||
let interfaces = platform.supported_interfaces().unwrap();
|
||||
log::debug!("Available interfaces: {interfaces:?}");
|
||||
// "Anime", "Aura", "FanCurves", "Platform"
|
||||
ui.set_sidebar_items_avilable(
|
||||
[
|
||||
// Needs to match the order of slint sidebar items
|
||||
interfaces.contains(&"Platform".into()),
|
||||
has_aura_iface_blocking().unwrap_or(false),
|
||||
interfaces.contains(&"Anime".into()),
|
||||
interfaces.contains(&"FanCurves".into()),
|
||||
has_iface_blocking("org.asuslinux.Platform").unwrap_or(false),
|
||||
has_iface_blocking("org.asuslinux.Aura").unwrap_or(false),
|
||||
has_iface_blocking("org.asuslinux.Anime").unwrap_or(false),
|
||||
has_iface_blocking("org.asuslinux.FanCurves").unwrap_or(false),
|
||||
true,
|
||||
true,
|
||||
]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use log::{error, info, warn};
|
||||
use rog_anime::Animations;
|
||||
use rog_dbus::zbus_anime::AnimeProxy;
|
||||
use slint::ComponentHandle;
|
||||
@@ -11,8 +12,13 @@ use crate::{set_ui_callbacks, set_ui_props_async, AnimePageData, MainWindow};
|
||||
pub fn setup_anime_page(ui: &MainWindow, _states: Arc<Mutex<Config>>) {
|
||||
let handle = ui.as_weak();
|
||||
tokio::spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let anime = AnimeProxy::new(&conn).await.unwrap();
|
||||
let Ok(conn) = zbus::Connection::system().await.map_err(|e| warn!("{e:}")) else {
|
||||
return;
|
||||
};
|
||||
let Ok(anime) = AnimeProxy::new(&conn).await.map_err(|e| warn!("{e:}")) else {
|
||||
info!("This device may not have an AniMe. If not then the error can be ignored");
|
||||
return;
|
||||
};
|
||||
|
||||
set_ui_props_async!(handle, anime, AnimePageData, brightness);
|
||||
set_ui_props_async!(handle, anime, AnimePageData, builtins_enabled);
|
||||
@@ -123,6 +129,7 @@ pub fn setup_anime_page(ui: &MainWindow, _states: Arc<Mutex<Config>>) {
|
||||
"Setting Anime off_when_unplugged failed"
|
||||
);
|
||||
})
|
||||
.unwrap();
|
||||
.map_err(|e| error!("setup_anime_page: upgrade_in_event_loop: {e:?}"))
|
||||
.ok();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use log::info;
|
||||
use log::{error, info};
|
||||
use rog_aura::keyboard::LaptopAuraPower;
|
||||
use rog_dbus::zbus_aura::AuraProxy;
|
||||
use slint::{ComponentHandle, Model, RgbaColor, SharedString};
|
||||
@@ -33,31 +33,11 @@ fn decode_hex(s: &str) -> RgbaColor<u8> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_aura_iface_blocking() -> Result<bool, Box<dyn std::error::Error>> {
|
||||
let conn = zbus::blocking::Connection::system()?;
|
||||
let f = zbus::blocking::fdo::ObjectManagerProxy::new(
|
||||
&conn,
|
||||
"org.asuslinux.Daemon",
|
||||
"/org/asuslinux",
|
||||
)?;
|
||||
let interfaces = f.get_managed_objects()?;
|
||||
let mut aura_paths = Vec::new();
|
||||
for v in interfaces.iter() {
|
||||
for k in v.1.keys() {
|
||||
if k.as_str() == "org.asuslinux.Aura" {
|
||||
aura_paths.push(v.0.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(!aura_paths.is_empty())
|
||||
}
|
||||
|
||||
/// Returns the first available Aura interface
|
||||
// TODO: return all
|
||||
async fn find_aura_iface() -> Result<AuraProxy<'static>, Box<dyn std::error::Error>> {
|
||||
let conn = zbus::Connection::system().await?;
|
||||
let f =
|
||||
zbus::fdo::ObjectManagerProxy::new(&conn, "org.asuslinux.Daemon", "/org/asuslinux").await?;
|
||||
let f = zbus::fdo::ObjectManagerProxy::new(&conn, "org.asuslinux.Daemon", "/").await?;
|
||||
let interfaces = f.get_managed_objects().await?;
|
||||
let mut aura_paths = Vec::new();
|
||||
for v in interfaces.iter() {
|
||||
@@ -93,9 +73,7 @@ pub fn setup_aura_page(ui: &MainWindow, _states: Arc<Mutex<Config>>) {
|
||||
|
||||
let handle = ui.as_weak();
|
||||
tokio::spawn(async move {
|
||||
let aura = if let Ok(aura) = find_aura_iface().await {
|
||||
aura
|
||||
} else {
|
||||
let Ok(aura) = find_aura_iface().await else {
|
||||
info!("This device appears to have no aura interfaces");
|
||||
return;
|
||||
};
|
||||
@@ -138,6 +116,7 @@ pub fn setup_aura_page(ui: &MainWindow, _states: Arc<Mutex<Config>>) {
|
||||
.global::<AuraPageData>()
|
||||
.set_available_mode_names(res.as_slice().into());
|
||||
})
|
||||
.map_err(|e| error!("{e:}"))
|
||||
.ok();
|
||||
}
|
||||
|
||||
@@ -196,7 +175,8 @@ pub fn setup_aura_page(ui: &MainWindow, _states: Arc<Mutex<Config>>) {
|
||||
});
|
||||
});
|
||||
})
|
||||
.unwrap();
|
||||
.map_err(|e| error!("{e:}"))
|
||||
.ok();
|
||||
|
||||
// Need to update the UI if the mode changes
|
||||
let handle_copy = handle.clone();
|
||||
@@ -213,6 +193,7 @@ pub fn setup_aura_page(ui: &MainWindow, _states: Arc<Mutex<Config>>) {
|
||||
.invoke_update_led_mode_data(out.into());
|
||||
handle.invoke_external_colour_change();
|
||||
})
|
||||
.map_err(|e| error!("{e:}"))
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use log::{error, info};
|
||||
use rog_dbus::zbus_fan_curves::FanCurvesProxy;
|
||||
use rog_platform::platform::ThrottlePolicy;
|
||||
use rog_profiles::fan_curve_set::CurveData;
|
||||
@@ -81,7 +82,8 @@ pub fn update_fan_data(
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
.map_err(|e| error!("update_fan_data: upgrade_in_event_loop: {e:?}"))
|
||||
.ok();
|
||||
}
|
||||
|
||||
pub fn setup_fan_curve_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) {
|
||||
@@ -89,17 +91,44 @@ pub fn setup_fan_curve_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) {
|
||||
|
||||
tokio::spawn(async move {
|
||||
// Create the connections/proxies here to prevent future delays in process
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let fans = FanCurvesProxy::new(&conn).await.unwrap();
|
||||
let conn = if let Ok(conn) = zbus::Connection::system().await.map_err(|e| error!("{e:}")) {
|
||||
conn
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
let fans = if let Ok(fans) = FanCurvesProxy::new(&conn).await.map_err(|e| error!("{e:}")) {
|
||||
fans
|
||||
} else {
|
||||
info!(
|
||||
"This device may not have an Fan Curve control. If not then the error can be \
|
||||
ignored"
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
let handle_copy = handle.clone();
|
||||
// Do initial setup
|
||||
let balanced = fans.fan_curve_data(ThrottlePolicy::Balanced).await.unwrap();
|
||||
let perf = fans
|
||||
let Ok(balanced) = fans
|
||||
.fan_curve_data(ThrottlePolicy::Balanced)
|
||||
.await
|
||||
.map_err(|e| error!("{e:}"))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Ok(perf) = fans
|
||||
.fan_curve_data(ThrottlePolicy::Performance)
|
||||
.await
|
||||
.unwrap();
|
||||
let quiet = fans.fan_curve_data(ThrottlePolicy::Quiet).await.unwrap();
|
||||
.map_err(|e| error!("{e:}"))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Ok(quiet) = fans
|
||||
.fan_curve_data(ThrottlePolicy::Quiet)
|
||||
.await
|
||||
.map_err(|e| error!("{e:}"))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
update_fan_data(handle, balanced, perf, quiet);
|
||||
|
||||
let handle_next1 = handle_copy.clone();
|
||||
@@ -111,14 +140,30 @@ pub fn setup_fan_curve_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) {
|
||||
let fans = fans1.clone();
|
||||
let handle_next = handle_next1.clone();
|
||||
tokio::spawn(async move {
|
||||
fans.set_curves_to_defaults(profile.into()).await.unwrap();
|
||||
|
||||
let balanced = fans.fan_curve_data(ThrottlePolicy::Balanced).await.unwrap();
|
||||
let perf = fans
|
||||
if fans.set_curves_to_defaults(profile.into()).await.is_err() {
|
||||
return;
|
||||
}
|
||||
let Ok(balanced) = fans
|
||||
.fan_curve_data(ThrottlePolicy::Balanced)
|
||||
.await
|
||||
.map_err(|e| error!("{e:}"))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Ok(perf) = fans
|
||||
.fan_curve_data(ThrottlePolicy::Performance)
|
||||
.await
|
||||
.unwrap();
|
||||
let quiet = fans.fan_curve_data(ThrottlePolicy::Quiet).await.unwrap();
|
||||
.map_err(|e| error!("{e:}"))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Ok(quiet) = fans
|
||||
.fan_curve_data(ThrottlePolicy::Quiet)
|
||||
.await
|
||||
.map_err(|e| error!("{e:}"))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
update_fan_data(handle_next, balanced, perf, quiet);
|
||||
});
|
||||
});
|
||||
@@ -127,11 +172,15 @@ pub fn setup_fan_curve_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) {
|
||||
let data: Vec<Node> = data.iter().collect();
|
||||
let data = fan_data_for(fan, enabled, data);
|
||||
tokio::spawn(async move {
|
||||
fans.set_fan_curve(profile.into(), data).await.unwrap();
|
||||
fans.set_fan_curve(profile.into(), data)
|
||||
.await
|
||||
.map_err(|e| error!("{e:}"))
|
||||
.ok()
|
||||
});
|
||||
});
|
||||
})
|
||||
.unwrap();
|
||||
.map_err(|e| error!("setup_fan_curve_page: upgrade_in_event_loop: {e:?}"))
|
||||
.ok();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user