Break config-traits out in to crate

This commit is contained in:
Luke D. Jones
2023-01-07 20:46:00 +13:00
parent ea5e5db490
commit 90b711c7b9
26 changed files with 161 additions and 110 deletions

View File

@@ -1,7 +1,11 @@
use std::path::PathBuf;
use config_traits::{StdConfig, StdConfigLoad1};
use rog_profiles::fan_curve_set::FanCurveSet;
use rog_profiles::{FanCurveProfiles, Profile};
use serde_derive::{Deserialize, Serialize};
use crate::config_traits::{StdConfig, StdConfigLoad1};
use crate::CONFIG_PATH_BASE;
const CONFIG_FILE: &str = "profile.conf";
const CONFIG_FAN_FILE: &str = "fan_curves.conf";
@@ -19,6 +23,10 @@ impl StdConfig for ProfileConfig {
}
}
fn config_dir() -> std::path::PathBuf {
PathBuf::from(CONFIG_PATH_BASE)
}
fn file_name() -> &'static str {
CONFIG_FILE
}
@@ -26,9 +34,46 @@ impl StdConfig for ProfileConfig {
impl StdConfigLoad1<ProfileConfig> for ProfileConfig {}
impl StdConfig for FanCurveProfiles {
#[derive(Deserialize, Serialize, Debug, Default)]
pub struct FanCurveConfig {
balanced: FanCurveSet,
performance: FanCurveSet,
quiet: FanCurveSet,
#[serde(skip)]
device: FanCurveProfiles,
}
impl FanCurveConfig {
pub fn update_device_config(&mut self) {
self.balanced = self.device.balanced.clone();
self.performance = self.device.performance.clone();
self.quiet = self.device.quiet.clone();
}
pub fn update_config(&mut self) {
self.balanced = self.device.balanced.clone();
self.performance = self.device.performance.clone();
self.quiet = self.device.quiet.clone();
}
pub fn device(&self) -> &FanCurveProfiles {
&self.device
}
pub fn device_mut(&mut self) -> &mut FanCurveProfiles {
&mut self.device
}
}
impl StdConfig for FanCurveConfig {
fn new() -> Self {
Self::default()
let mut tmp = Self::default();
tmp.update_device_config();
tmp
}
fn config_dir() -> std::path::PathBuf {
PathBuf::from(CONFIG_PATH_BASE)
}
fn file_name() -> &'static str {
@@ -36,4 +81,4 @@ impl StdConfig for FanCurveProfiles {
}
}
impl StdConfigLoad1<ProfileConfig> for FanCurveProfiles {}
impl StdConfigLoad1<ProfileConfig> for FanCurveConfig {}