mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
Reload asusd.ron if changed
This commit is contained in:
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Don't change EPP or thermal profile if the battery/ac state hasn't actually changed on resume
|
||||
- Re-implement the `asusctl -s` command (not fully)
|
||||
- Add more docs to some parts of code, and dbus interfaces
|
||||
- Reload asusd.ron if changed. Does not notify any dbus listeners (yet)
|
||||
|
||||
## [v5.0.7]
|
||||
### Changed
|
||||
|
||||
29
Cargo.lock
generated
29
Cargo.lock
generated
@@ -199,7 +199,7 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||
|
||||
[[package]]
|
||||
name = "asusctl"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"asusd",
|
||||
"cargo-husky",
|
||||
@@ -219,14 +219,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "asusd"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"cargo-husky",
|
||||
"concat-idents",
|
||||
"config-traits",
|
||||
"dmi_id",
|
||||
"env_logger",
|
||||
"futures-lite 2.2.0",
|
||||
"futures-lite 1.13.0",
|
||||
"inotify",
|
||||
"log",
|
||||
"logind-zbus",
|
||||
"rog_anime",
|
||||
@@ -243,7 +244,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "asusd-user"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"cargo-husky",
|
||||
"config-traits",
|
||||
@@ -846,7 +847,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "config-traits"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"cargo-husky",
|
||||
"log",
|
||||
@@ -899,7 +900,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cpuctl"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
@@ -1023,7 +1024,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "dmi_id"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"log",
|
||||
"udev",
|
||||
@@ -2833,7 +2834,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "rog-control-center"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"asusd",
|
||||
"cargo-husky",
|
||||
@@ -2866,7 +2867,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rog_anime"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"cargo-husky",
|
||||
"dmi_id",
|
||||
@@ -2883,7 +2884,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rog_aura"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"cargo-husky",
|
||||
"dmi_id",
|
||||
@@ -2897,7 +2898,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rog_dbus"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"asusd",
|
||||
"cargo-husky",
|
||||
@@ -2910,7 +2911,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rog_platform"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"cargo-husky",
|
||||
"concat-idents",
|
||||
@@ -2927,7 +2928,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rog_profiles"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"cargo-husky",
|
||||
"log",
|
||||
@@ -2941,7 +2942,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rog_simulators"
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
dependencies = [
|
||||
"glam",
|
||||
"log",
|
||||
|
||||
@@ -4,7 +4,7 @@ default-members = ["asusctl", "asusd", "asusd-user", "cpuctl", "rog-control-cent
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
version = "5.0.7"
|
||||
version = "5.0.8-RC1"
|
||||
rust-version = "1.75"
|
||||
|
||||
[workspace.dependencies]
|
||||
|
||||
@@ -22,6 +22,7 @@ rog_profiles = { path = "../rog-profiles" }
|
||||
dmi_id = { path = "../dmi-id" }
|
||||
futures-lite = "*"
|
||||
udev.workspace = true
|
||||
inotify.workspace = true
|
||||
|
||||
tokio.workspace = true
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
const CONFIG_FILE: &str = "asusd.ron";
|
||||
|
||||
#[derive(Deserialize, Serialize, Default, Debug)]
|
||||
#[derive(Deserialize, Serialize, Default, Debug, PartialEq, PartialOrd)]
|
||||
pub struct Config {
|
||||
/// Save charge limit for restoring on boot/resume
|
||||
pub charge_control_end_threshold: u8,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -15,7 +16,7 @@ use crate::ctrl_anime::trait_impls::{CtrlAnimeZbus, ANIME_ZBUS_NAME, ANIME_ZBUS_
|
||||
use crate::ctrl_aura::trait_impls::{CtrlAuraZbus, AURA_ZBUS_NAME, AURA_ZBUS_PATH};
|
||||
use crate::ctrl_fancurves::{CtrlFanCurveZbus, FAN_CURVE_ZBUS_NAME, FAN_CURVE_ZBUS_PATH};
|
||||
use crate::error::RogError;
|
||||
use crate::{task_watch_item, task_watch_item_notify, CtrlTask};
|
||||
use crate::{task_watch_item, task_watch_item_notify, CtrlTask, Reloadable};
|
||||
|
||||
const PLATFORM_ZBUS_NAME: &str = "Platform";
|
||||
const PLATFORM_ZBUS_PATH: &str = "/org/asuslinux/Platform";
|
||||
@@ -115,7 +116,7 @@ pub struct CtrlPlatform {
|
||||
}
|
||||
|
||||
impl CtrlPlatform {
|
||||
pub fn new(config: Arc<Mutex<Config>>) -> Result<Self, RogError> {
|
||||
pub fn new(config: Arc<Mutex<Config>>, config_path: &Path) -> Result<Self, RogError> {
|
||||
let platform = RogPlatform::new()?;
|
||||
let power = AsusPower::new()?;
|
||||
|
||||
@@ -124,14 +125,60 @@ impl CtrlPlatform {
|
||||
info!("Standard graphics switching will still work.");
|
||||
}
|
||||
|
||||
Ok(CtrlPlatform {
|
||||
let config1 = config.clone();
|
||||
let inotify = inotify::Inotify::init()?;
|
||||
inotify
|
||||
.watches()
|
||||
.add(config_path, inotify::WatchMask::MODIFY)
|
||||
.map_err(|e| {
|
||||
if e.kind() == std::io::ErrorKind::NotFound {
|
||||
error!("Not found: {:?}", config_path);
|
||||
} else {
|
||||
error!("Could not set asusd config inotify: {:?}", config_path);
|
||||
}
|
||||
e
|
||||
})
|
||||
.ok();
|
||||
|
||||
let ret_self = CtrlPlatform {
|
||||
power,
|
||||
platform,
|
||||
config,
|
||||
cpu_control: CPUControl::new()
|
||||
.map_err(|e| error!("Couldn't get CPU control sysfs: {e}"))
|
||||
.ok(),
|
||||
};
|
||||
let inotify_self = ret_self.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
use zbus::export::futures_util::StreamExt;
|
||||
info!("Starting inotify watch for asusd config file");
|
||||
|
||||
let mut buffer = [0; 32];
|
||||
inotify
|
||||
.into_event_stream(&mut buffer)
|
||||
.unwrap()
|
||||
.for_each(|_| async {
|
||||
let res = config1.lock().await.read_new();
|
||||
if let Some(new_cfg) = res {
|
||||
let mut old_cfg = config1.lock().await;
|
||||
if *old_cfg != new_cfg {
|
||||
info!(
|
||||
"asusd.ron updated externally, updating internal copy and \
|
||||
reloading"
|
||||
);
|
||||
*old_cfg = new_cfg;
|
||||
// shitty way to handle this but it works. Only require the reload()
|
||||
let mut inotify_self = inotify_self.clone();
|
||||
// TODO: better reload with ReloadAndNotify
|
||||
inotify_self.reload().await.unwrap();
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
});
|
||||
|
||||
Ok(ret_self)
|
||||
}
|
||||
|
||||
fn set_gfx_mode(&self, mode: GpuMode) -> Result<(), RogError> {
|
||||
|
||||
@@ -64,11 +64,12 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
let mut connection = Connection::system().await?;
|
||||
|
||||
let config = Config::new().load();
|
||||
let cfg_path = config.file_path();
|
||||
let config = Arc::new(Mutex::new(config));
|
||||
|
||||
// supported.add_to_server(&mut connection).await;
|
||||
|
||||
match CtrlPlatform::new(config.clone()) {
|
||||
match CtrlPlatform::new(config.clone(), &cfg_path) {
|
||||
Ok(ctrl) => {
|
||||
let sig_ctx = CtrlPlatform::signal_context(&connection)?;
|
||||
start_tasks(ctrl, &mut connection, sig_ctx).await?;
|
||||
|
||||
@@ -132,6 +132,14 @@ pub fn print_board_info() {
|
||||
pub trait Reloadable {
|
||||
fn reload(&mut self) -> impl std::future::Future<Output = Result<(), RogError>> + Send;
|
||||
}
|
||||
|
||||
pub trait ReloadAndNotify {
|
||||
fn reload_and_notify(
|
||||
&mut self,
|
||||
signal_context: SignalContext<'static>,
|
||||
) -> impl std::future::Future<Output = Result<(), RogError>> + Send;
|
||||
}
|
||||
|
||||
pub trait ZbusRun {
|
||||
fn add_to_server(self, server: &mut Connection)
|
||||
-> impl std::future::Future<Output = ()> + Send;
|
||||
|
||||
@@ -109,6 +109,20 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Open and parse the config file to self from ron format
|
||||
fn read_new(&self) -> Option<Self> {
|
||||
if let Ok(data) = fs::read_to_string(self.file_path()) {
|
||||
if data.is_empty() {
|
||||
warn!("File is empty {:?}", self.file_path());
|
||||
} else if let Ok(data) = ron::from_str(&data) {
|
||||
return Some(data);
|
||||
} else {
|
||||
warn!("Could not deserialise {:?}", self.file_path());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Write the config file data to pretty ron format
|
||||
fn write(&self) {
|
||||
let mut file = match File::create(self.file_path()) {
|
||||
|
||||
Reference in New Issue
Block a user