mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
@@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Changed
|
### Changed
|
||||||
|
- Better handling of `/etc/asusd` not existing
|
||||||
|
- Better handling of non-existant config files
|
||||||
- Added option to set `disable_nvidia_powerd_on_battery`
|
- Added option to set `disable_nvidia_powerd_on_battery`
|
||||||
- Add short log entry to throttle_thermal_policy change detection
|
- Add short log entry to throttle_thermal_policy change detection
|
||||||
- ROGCC: Don't notify user if changing to same mux mode
|
- ROGCC: Don't notify user if changing to same mux mode
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf";
|
use crate::config_file_open;
|
||||||
|
|
||||||
|
pub static CONFIG_FILE: &str = "/etc/asusd/asusd.conf";
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Default)]
|
#[derive(Deserialize, Serialize, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
@@ -30,12 +31,7 @@ impl Config {
|
|||||||
|
|
||||||
/// `load` will attempt to read the config, and panic if the dir is missing
|
/// `load` will attempt to read the config, and panic if the dir is missing
|
||||||
pub fn load() -> Self {
|
pub fn load() -> Self {
|
||||||
let mut file = OpenOptions::new()
|
let mut file = config_file_open(CONFIG_FILE);
|
||||||
.read(true)
|
|
||||||
.write(true)
|
|
||||||
.create(true)
|
|
||||||
.open(&PathBuf::from(CONFIG_PATH))
|
|
||||||
.unwrap_or_else(|e| panic!("Error opening {}, {}", CONFIG_PATH, e)); // okay to cause panic here
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
let config;
|
let config;
|
||||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||||
@@ -50,13 +46,13 @@ impl Config {
|
|||||||
} else {
|
} else {
|
||||||
warn!(
|
warn!(
|
||||||
"Could not deserialise {}.\nWill rename to {}-old and recreate config",
|
"Could not deserialise {}.\nWill rename to {}-old and recreate config",
|
||||||
CONFIG_PATH, CONFIG_PATH
|
CONFIG_FILE, CONFIG_FILE
|
||||||
);
|
);
|
||||||
let cfg_old = CONFIG_PATH.to_owned() + "-old";
|
let cfg_old = CONFIG_FILE.to_owned() + "-old";
|
||||||
std::fs::rename(CONFIG_PATH, cfg_old).unwrap_or_else(|err| {
|
std::fs::rename(CONFIG_FILE, cfg_old).unwrap_or_else(|err| {
|
||||||
panic!(
|
panic!(
|
||||||
"Could not rename. Please remove {} then restart service: Error {}",
|
"Could not rename. Please remove {} then restart service: Error {}",
|
||||||
CONFIG_PATH, err
|
CONFIG_FILE, err
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
config = Self::new();
|
config = Self::new();
|
||||||
@@ -71,21 +67,21 @@ impl Config {
|
|||||||
pub fn read(&mut self) {
|
pub fn read(&mut self) {
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.open(CONFIG_PATH)
|
.open(CONFIG_FILE)
|
||||||
.unwrap_or_else(|err| panic!("Error reading {}: {}", CONFIG_PATH, err));
|
.unwrap_or_else(|err| panic!("Error reading {}: {}", CONFIG_FILE, err));
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Ok(l) = file.read_to_string(&mut buf) {
|
if let Ok(l) = file.read_to_string(&mut buf) {
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
warn!("File is empty {}", CONFIG_PATH);
|
warn!("File is empty {}", CONFIG_FILE);
|
||||||
} else {
|
} else {
|
||||||
*self = serde_json::from_str(&buf)
|
*self = serde_json::from_str(&buf)
|
||||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
|
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_FILE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&self) {
|
pub fn write(&self) {
|
||||||
let mut file = File::create(CONFIG_PATH).expect("Couldn't overwrite config");
|
let mut file = File::create(CONFIG_FILE).expect("Couldn't overwrite config");
|
||||||
let json = serde_json::to_string_pretty(self).expect("Parse config to JSON failed");
|
let json = serde_json::to_string_pretty(self).expect("Parse config to JSON failed");
|
||||||
file.write_all(json.as_bytes())
|
file.write_all(json.as_bytes())
|
||||||
.unwrap_or_else(|err| error!("Could not write config: {}", err));
|
.unwrap_or_else(|err| error!("Could not write config: {}", err));
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ use rog_anime::error::AnimeError;
|
|||||||
use rog_anime::{ActionData, ActionLoader, AnimTime, AnimeType, Fade, Vec2};
|
use rog_anime::{ActionData, ActionLoader, AnimTime, AnimeType, Fade, Vec2};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::VERSION;
|
use crate::{config_file_open, VERSION};
|
||||||
|
|
||||||
pub static ANIME_CONFIG_PATH: &str = "/etc/asusd/anime.conf";
|
pub static CONFIG_FILE: &str = "anime.conf";
|
||||||
pub static ANIME_CACHE_PATH: &str = "/etc/asusd/anime-cache.conf";
|
pub static ANIME_CACHE_PATH: &str = "/etc/asusd/anime-cache.conf";
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
@@ -143,17 +143,7 @@ impl Default for AnimeConfig {
|
|||||||
impl AnimeConfig {
|
impl AnimeConfig {
|
||||||
/// `load` will attempt to read the config, and panic if the dir is missing
|
/// `load` will attempt to read the config, and panic if the dir is missing
|
||||||
pub fn load() -> Self {
|
pub fn load() -> Self {
|
||||||
let mut file = OpenOptions::new()
|
let mut file = config_file_open(CONFIG_FILE);
|
||||||
.read(true)
|
|
||||||
.write(true)
|
|
||||||
.create(true)
|
|
||||||
.open(ANIME_CONFIG_PATH)
|
|
||||||
.unwrap_or_else(|_| {
|
|
||||||
panic!(
|
|
||||||
"The file {} or directory /etc/asusd/ is missing",
|
|
||||||
ANIME_CONFIG_PATH
|
|
||||||
)
|
|
||||||
}); // okay to cause panic here
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||||
if read_len == 0 {
|
if read_len == 0 {
|
||||||
@@ -177,13 +167,13 @@ impl AnimeConfig {
|
|||||||
}
|
}
|
||||||
warn!(
|
warn!(
|
||||||
"Could not deserialise {}.\nWill rename to {}-old and recreate config",
|
"Could not deserialise {}.\nWill rename to {}-old and recreate config",
|
||||||
ANIME_CONFIG_PATH, ANIME_CONFIG_PATH
|
CONFIG_FILE, CONFIG_FILE
|
||||||
);
|
);
|
||||||
let cfg_old = ANIME_CONFIG_PATH.to_string() + "-old";
|
let cfg_old = CONFIG_FILE.to_string() + "-old";
|
||||||
std::fs::rename(ANIME_CONFIG_PATH, cfg_old).unwrap_or_else(|err| {
|
std::fs::rename(CONFIG_FILE, cfg_old).unwrap_or_else(|err| {
|
||||||
panic!(
|
panic!(
|
||||||
"Could not rename. Please remove {} then restart service: Error {}",
|
"Could not rename. Please remove {} then restart service: Error {}",
|
||||||
ANIME_CONFIG_PATH, err
|
CONFIG_FILE, err
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -244,29 +234,29 @@ impl AnimeConfig {
|
|||||||
// Should be okay to unwrap this as is since it is a Default
|
// Should be okay to unwrap this as is since it is a Default
|
||||||
let json = serde_json::to_string_pretty(&config).unwrap();
|
let json = serde_json::to_string_pretty(&config).unwrap();
|
||||||
file.write_all(json.as_bytes())
|
file.write_all(json.as_bytes())
|
||||||
.unwrap_or_else(|_| panic!("Could not write {}", ANIME_CONFIG_PATH));
|
.unwrap_or_else(|_| panic!("Could not write {}", CONFIG_FILE));
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&mut self) {
|
pub fn read(&mut self) {
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.open(ANIME_CONFIG_PATH)
|
.open(CONFIG_FILE)
|
||||||
.unwrap_or_else(|err| panic!("Error reading {}: {}", ANIME_CONFIG_PATH, err));
|
.unwrap_or_else(|err| panic!("Error reading {}: {}", CONFIG_FILE, err));
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Ok(l) = file.read_to_string(&mut buf) {
|
if let Ok(l) = file.read_to_string(&mut buf) {
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
warn!("File is empty {}", ANIME_CONFIG_PATH);
|
warn!("File is empty {}", CONFIG_FILE);
|
||||||
} else {
|
} else {
|
||||||
let x: AnimeConfig = serde_json::from_str(&buf)
|
let x: AnimeConfig = serde_json::from_str(&buf)
|
||||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", ANIME_CONFIG_PATH));
|
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_FILE));
|
||||||
*self = x;
|
*self = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&self) {
|
pub fn write(&self) {
|
||||||
let mut file = File::create(ANIME_CONFIG_PATH).expect("Couldn't overwrite config");
|
let mut file = File::create(CONFIG_FILE).expect("Couldn't overwrite config");
|
||||||
let json = serde_json::to_string_pretty(self).expect("Parse config to JSON failed");
|
let json = serde_json::to_string_pretty(self).expect("Parse config to JSON failed");
|
||||||
file.write_all(json.as_bytes())
|
file.write_all(json.as_bytes())
|
||||||
.unwrap_or_else(|err| error!("Could not write config: {}", err));
|
.unwrap_or_else(|err| error!("Could not write config: {}", err));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::collections::{BTreeMap, HashSet};
|
use std::collections::{BTreeMap, HashSet};
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
@@ -10,7 +10,9 @@ use rog_platform::hid_raw::HidRaw;
|
|||||||
use rog_platform::keyboard_led::KeyboardLed;
|
use rog_platform::keyboard_led::KeyboardLed;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub static AURA_CONFIG_PATH: &str = "/etc/asusd/aura.conf";
|
use crate::config_file_open;
|
||||||
|
|
||||||
|
static CONFIG_FILE: &str = "aura.conf";
|
||||||
|
|
||||||
/// Enable/disable LED control in various states such as
|
/// Enable/disable LED control in various states such as
|
||||||
/// when the device is awake, suspended, shutting down or
|
/// when the device is awake, suspended, shutting down or
|
||||||
@@ -190,17 +192,7 @@ impl Default for AuraConfig {
|
|||||||
impl AuraConfig {
|
impl AuraConfig {
|
||||||
/// `load` will attempt to read the config, and panic if the dir is missing
|
/// `load` will attempt to read the config, and panic if the dir is missing
|
||||||
pub fn load(supported_led_modes: &LaptopLedData) -> Self {
|
pub fn load(supported_led_modes: &LaptopLedData) -> Self {
|
||||||
let mut file = OpenOptions::new()
|
let mut file = config_file_open(CONFIG_FILE);
|
||||||
.read(true)
|
|
||||||
.write(true)
|
|
||||||
.create(true)
|
|
||||||
.open(AURA_CONFIG_PATH)
|
|
||||||
.unwrap_or_else(|_| {
|
|
||||||
panic!(
|
|
||||||
"The file {} or directory /etc/asusd/ is missing",
|
|
||||||
AURA_CONFIG_PATH
|
|
||||||
)
|
|
||||||
}); // okay to cause panic here
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||||
if read_len == 0 {
|
if read_len == 0 {
|
||||||
@@ -211,13 +203,13 @@ impl AuraConfig {
|
|||||||
}
|
}
|
||||||
warn!(
|
warn!(
|
||||||
"Could not deserialise {}.\nWill rename to {}-old and recreate config",
|
"Could not deserialise {}.\nWill rename to {}-old and recreate config",
|
||||||
AURA_CONFIG_PATH, AURA_CONFIG_PATH
|
CONFIG_FILE, CONFIG_FILE
|
||||||
);
|
);
|
||||||
let cfg_old = AURA_CONFIG_PATH.to_string() + "-old";
|
let cfg_old = CONFIG_FILE.to_string() + "-old";
|
||||||
std::fs::rename(AURA_CONFIG_PATH, cfg_old).unwrap_or_else(|err| {
|
std::fs::rename(CONFIG_FILE, cfg_old).unwrap_or_else(|err| {
|
||||||
panic!(
|
panic!(
|
||||||
"Could not rename. Please remove {} then restart service: Error {}",
|
"Could not rename. Please remove {} then restart service: Error {}",
|
||||||
AURA_CONFIG_PATH, err
|
CONFIG_FILE, err
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -259,29 +251,26 @@ impl AuraConfig {
|
|||||||
// Should be okay to unwrap this as is since it is a Default
|
// Should be okay to unwrap this as is since it is a Default
|
||||||
let json = serde_json::to_string(&config).unwrap();
|
let json = serde_json::to_string(&config).unwrap();
|
||||||
file.write_all(json.as_bytes())
|
file.write_all(json.as_bytes())
|
||||||
.unwrap_or_else(|_| panic!("Could not write {}", AURA_CONFIG_PATH));
|
.unwrap_or_else(|_| panic!("Could not write {}", CONFIG_FILE));
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&mut self) {
|
pub fn read(&mut self) {
|
||||||
let mut file = OpenOptions::new()
|
let mut file = config_file_open(CONFIG_FILE);
|
||||||
.read(true)
|
|
||||||
.open(AURA_CONFIG_PATH)
|
|
||||||
.unwrap_or_else(|err| panic!("Error reading {}: {}", AURA_CONFIG_PATH, err));
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Ok(l) = file.read_to_string(&mut buf) {
|
if let Ok(l) = file.read_to_string(&mut buf) {
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
warn!("File is empty {}", AURA_CONFIG_PATH);
|
warn!("File is empty {}", CONFIG_FILE);
|
||||||
} else {
|
} else {
|
||||||
let x = serde_json::from_str(&buf)
|
let x = serde_json::from_str(&buf)
|
||||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", AURA_CONFIG_PATH));
|
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_FILE));
|
||||||
*self = x;
|
*self = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(&self) {
|
pub fn write(&self) {
|
||||||
let mut file = File::create(AURA_CONFIG_PATH).expect("Couldn't overwrite config");
|
let mut file = File::create(CONFIG_FILE).expect("Couldn't overwrite config");
|
||||||
let json = serde_json::to_string_pretty(self).expect("Parse config to JSON failed");
|
let json = serde_json::to_string_pretty(self).expect("Parse config to JSON failed");
|
||||||
file.write_all(json.as_bytes())
|
file.write_all(json.as_bytes())
|
||||||
.unwrap_or_else(|err| error!("Could not write config: {}", err));
|
.unwrap_or_else(|err| error!("Could not write config: {}", err));
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use rog_profiles::{FanCurveProfiles, Profile};
|
use rog_profiles::{FanCurveProfiles, Profile};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::{config_file, config_file_open};
|
||||||
|
|
||||||
|
static CONFIG_FILE: &str = "profile.conf";
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
pub struct ProfileConfig {
|
pub struct ProfileConfig {
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
config_path: String,
|
config_path: PathBuf,
|
||||||
/// For restore on boot
|
/// For restore on boot
|
||||||
pub active_profile: Profile,
|
pub active_profile: Profile,
|
||||||
/// States to restore
|
/// States to restore
|
||||||
@@ -16,7 +21,7 @@ pub struct ProfileConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ProfileConfig {
|
impl ProfileConfig {
|
||||||
fn new(config_path: String) -> Self {
|
fn new(config_path: PathBuf) -> Self {
|
||||||
Self {
|
Self {
|
||||||
config_path,
|
config_path,
|
||||||
active_profile: Profile::Balanced,
|
active_profile: Profile::Balanced,
|
||||||
@@ -24,13 +29,9 @@ impl ProfileConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(config_path: String) -> Self {
|
pub fn load() -> Self {
|
||||||
let mut file = OpenOptions::new()
|
let config_path = config_file(CONFIG_FILE);
|
||||||
.read(true)
|
let mut file = config_file_open(CONFIG_FILE);
|
||||||
.write(true)
|
|
||||||
.create(true)
|
|
||||||
.open(&config_path)
|
|
||||||
.unwrap_or_else(|_| panic!("The directory /etc/asusd/ is missing")); // okay to cause panic here
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
let mut config;
|
let mut config;
|
||||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||||
@@ -41,15 +42,15 @@ impl ProfileConfig {
|
|||||||
config.config_path = config_path;
|
config.config_path = config_path;
|
||||||
} else {
|
} else {
|
||||||
warn!(
|
warn!(
|
||||||
"Could not deserialise {}.\nWill rename to {}-old and recreate config",
|
"Could not deserialise {config_path:?}.\nWill rename to {config_path:?}-old \
|
||||||
config_path, config_path
|
and recreate config",
|
||||||
);
|
);
|
||||||
let mut cfg_old = config_path.clone();
|
let mut cfg_old = config_path.clone();
|
||||||
cfg_old.push_str("-old");
|
cfg_old.push("-old");
|
||||||
std::fs::rename(config_path.clone(), cfg_old).unwrap_or_else(|err| {
|
std::fs::rename(config_path.clone(), cfg_old).unwrap_or_else(|err| {
|
||||||
panic!(
|
panic!(
|
||||||
"Could not rename. Please remove {} then restart service: Error {}",
|
"Could not rename. Please remove {config_path:?} then restart service: \
|
||||||
config_path, err
|
Error {err}",
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
config = Self::new(config_path);
|
config = Self::new(config_path);
|
||||||
@@ -64,15 +65,15 @@ impl ProfileConfig {
|
|||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.open(&self.config_path)
|
.open(&self.config_path)
|
||||||
.unwrap_or_else(|err| panic!("Error reading {}: {}", self.config_path, err));
|
.unwrap_or_else(|err| panic!("Error reading {:?}: {}", self.config_path, err));
|
||||||
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Ok(l) = file.read_to_string(&mut buf) {
|
if let Ok(l) = file.read_to_string(&mut buf) {
|
||||||
if l == 0 {
|
if l == 0 {
|
||||||
warn!("File is empty {}", self.config_path);
|
warn!("File is empty {:?}", self.config_path);
|
||||||
} else {
|
} else {
|
||||||
let mut data: ProfileConfig = toml::from_str(&buf)
|
let mut data: ProfileConfig = toml::from_str(&buf)
|
||||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", self.config_path));
|
.unwrap_or_else(|_| panic!("Could not deserialise {:?}", self.config_path));
|
||||||
// copy over serde skipped values
|
// copy over serde skipped values
|
||||||
data.config_path = self.config_path.clone();
|
data.config_path = self.config_path.clone();
|
||||||
*self = data;
|
*self = data;
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ use rog_profiles::Profile;
|
|||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use zbus::SignalContext;
|
use zbus::SignalContext;
|
||||||
|
|
||||||
static PROFILE_CONFIG_PATH: &str = "/etc/asusd/profile.conf";
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut logger = env_logger::Builder::new();
|
let mut logger = env_logger::Builder::new();
|
||||||
@@ -98,7 +96,7 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if Profile::is_platform_profile_supported() {
|
if Profile::is_platform_profile_supported() {
|
||||||
let profile_config = ProfileConfig::load(PROFILE_CONFIG_PATH.into());
|
let profile_config = ProfileConfig::load();
|
||||||
match CtrlPlatformProfile::new(profile_config) {
|
match CtrlPlatformProfile::new(profile_config) {
|
||||||
Ok(ctrl) => {
|
Ok(ctrl) => {
|
||||||
let zbus = ProfileZbus(Arc::new(Mutex::new(ctrl)));
|
let zbus = ProfileZbus(Arc::new(Mutex::new(ctrl)));
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ pub mod ctrl_supported;
|
|||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
|
||||||
|
use std::fs::{create_dir, File, OpenOptions};
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
@@ -28,6 +30,30 @@ use zbus::{Connection, SignalContext};
|
|||||||
|
|
||||||
use crate::error::RogError;
|
use crate::error::RogError;
|
||||||
|
|
||||||
|
static CONFIG_PATH_BASE: &str = "/etc/asusd/";
|
||||||
|
|
||||||
|
/// Create a `PathBuf` for `file`. If the base config dir `CONFIG_PATH_BASE`
|
||||||
|
/// does not exist it is created.
|
||||||
|
fn config_file(file: &str) -> PathBuf {
|
||||||
|
let mut config = PathBuf::from(CONFIG_PATH_BASE);
|
||||||
|
if !config.exists() {
|
||||||
|
create_dir(config.as_path()).unwrap_or_else(|_| panic!("Could not create {config:?}"));
|
||||||
|
}
|
||||||
|
config.push(file);
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Open a config file as read/write. If the file or dir does not exist then
|
||||||
|
/// both are created.
|
||||||
|
pub fn config_file_open(file: &str) -> File {
|
||||||
|
OpenOptions::new()
|
||||||
|
.read(true)
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.open(config_file(file))
|
||||||
|
.unwrap_or_else(|_| panic!("The file {file} or directory {CONFIG_PATH_BASE} is missing"))
|
||||||
|
}
|
||||||
|
|
||||||
/// This macro adds a function which spawns an `inotify` task on the passed in
|
/// This macro adds a function which spawns an `inotify` task on the passed in
|
||||||
/// `Executor`.
|
/// `Executor`.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user