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:
parent
661d608788
commit
c50f5c8812
3 changed files with 19 additions and 11 deletions
|
@ -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 },
|
||||
]
|
||||
|
|
|
@ -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(|| {
|
||||
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());
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue