1
Fork 0
mirror of https://github.com/RGBCube/superfreq synced 2025-07-27 17:07:44 +00:00

config: integrate default config

This commit is contained in:
RGBCube 2025-06-11 23:54:19 +03:00
parent 661d608788
commit c50f5c8812
Signed by: RGBCube
SSH key fingerprint: SHA256:CzqbPcfwt+GxFYNnFVCqoN5Itn4YFrshg1TrnACpA5M
3 changed files with 19 additions and 11 deletions

View file

@ -37,11 +37,11 @@ cpu.governor = "performance"
cpu.energy-performance-preference = "performance"
cpu.turbo = true
# Performance mode when charging.
# Performance mode when not discharging.
[[rule]]
priority = 70
if.all = [
"?charging",
{ not = "?discharging" },
{ value = "%cpu-usage", is-more-than = 0.1 },
{ value = "$cpu-temperature", is-less-than = 80.0 },
]

View file

@ -471,13 +471,21 @@ pub struct DaemonConfig {
}
impl DaemonConfig {
pub fn load_from(path: &Path) -> anyhow::Result<Self> {
let contents = fs::read_to_string(path).with_context(|| {
format!("failed to read config from '{path}'", path = path.display())
})?;
pub fn load_from(path: Option<&Path>) -> anyhow::Result<Self> {
let contents = if let Some(path) = path {
&fs::read_to_string(path).with_context(|| {
format!("failed to read config from '{path}'", path = path.display())
})?
} else {
include_str!("../config.toml")
};
let mut config: Self = toml::from_str(&contents)
.with_context(|| format!("failed to parse file at '{path}'", path = path.display(),))?;
let mut config: Self = toml::from_str(contents).with_context(|| {
path.map_or(
"failed to parse builtin default config, this is a bug".to_owned(),
|p| format!("failed to parse file at '{path}'", path = p.display()),
)
})?;
{
let mut priorities = Vec::with_capacity(config.rules.len());

View file

@ -35,7 +35,7 @@ enum Command {
/// The daemon config path.
#[arg(long, env = "WATT_CONFIG")]
config: PathBuf,
config: Option<PathBuf>,
},
/// CPU metadata and modification utility.
@ -86,8 +86,8 @@ fn real_main() -> anyhow::Result<()> {
match cli.command {
Command::Watt { config, .. } => {
let config =
config::DaemonConfig::load_from(&config).context("failed to load daemon config")?;
let config = config::DaemonConfig::load_from(config.as_deref())
.context("failed to load daemon config")?;
daemon::run(config)
}