mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fetch and store fan curve correctly
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use log::{error, warn};
|
||||
use rog_profiles::fan_curves::FanCurveSet;
|
||||
use rog_profiles::{FanCurves, Profile};
|
||||
use rog_profiles::fan_curve_set::FanCurveSet;
|
||||
use rog_profiles::{FanCurveProfiles, Profile};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Write};
|
||||
@@ -12,20 +12,20 @@ pub struct ProfileConfig {
|
||||
/// For restore on boot
|
||||
pub active_profile: Profile,
|
||||
/// States to restore
|
||||
pub fan_curves: Option<FanCurves>,
|
||||
pub fan_curves: Option<FanCurveProfiles>,
|
||||
}
|
||||
|
||||
impl ProfileConfig {
|
||||
fn new(config_path: String) -> Self {
|
||||
let mut platform = ProfileConfig {
|
||||
config_path,
|
||||
active_profile: Profile::Balanced,
|
||||
active_profile: Profile::get_active_profile().unwrap_or(Profile::Balanced),
|
||||
fan_curves: None,
|
||||
};
|
||||
|
||||
if let Ok(res) = FanCurveSet::is_supported() {
|
||||
if res {
|
||||
let curves = FanCurves::default();
|
||||
let curves = FanCurveProfiles::default();
|
||||
platform.fan_curves = Some(curves);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ impl ProfileConfig {
|
||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||
if read_len == 0 {
|
||||
config = Self::new(config_path);
|
||||
} else if let Ok(data) = serde_json::from_str(&buf) {
|
||||
} else if let Ok(data) = toml::from_str(&buf) {
|
||||
config = data;
|
||||
config.config_path = config_path;
|
||||
} else {
|
||||
@@ -70,7 +70,7 @@ impl ProfileConfig {
|
||||
if l == 0 {
|
||||
warn!("File is empty {}", self.config_path);
|
||||
} else {
|
||||
let mut data: ProfileConfig = serde_json::from_str(&buf)
|
||||
let mut data: ProfileConfig = toml::from_str(&buf)
|
||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", self.config_path));
|
||||
// copy over serde skipped values
|
||||
data.config_path = self.config_path.clone();
|
||||
@@ -81,8 +81,8 @@ impl ProfileConfig {
|
||||
|
||||
pub fn write(&self) {
|
||||
let mut file = File::create(&self.config_path).expect("Couldn't overwrite config");
|
||||
let json = serde_json::to_string_pretty(self).expect("Parse config to JSON failed");
|
||||
file.write_all(json.as_bytes())
|
||||
let data = toml::to_string(self).expect("Parse config to toml failed");
|
||||
file.write_all(data.as_bytes())
|
||||
.unwrap_or_else(|err| error!("Could not write config: {}", err));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user