Pass config from main to the relevant places

This commit is contained in:
jmb05
2026-11-02 17:06:42 +01:00
parent de1f731e63
commit cdfc5b8d36
13 changed files with 170 additions and 107 deletions

View File

@@ -1,23 +1,9 @@
use serde::Deserialize;
use std::fs;
#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, Default)]
pub(crate) struct Config {
idle_timeout: u64,
dim_timeout: u64,
lock_timeout: u64,
sleep_timeout: u64,
}
impl Default for Config {
fn default() -> Self {
Self {
idle_timeout: 20,
dim_timeout: 60,
lock_timeout: 300,
sleep_timeout: 320,
}
}
pub idle: IdleConfig,
}
impl Config {
@@ -28,7 +14,31 @@ impl Config {
.flatten()
.unwrap_or_default()
}
}
#[derive(Deserialize, Debug, Clone)]
pub(crate) struct IdleConfig {
idle_timeout: u64,
dim_timeout: u64,
lock_timeout: u64,
sleep_timeout: u64,
lock_command: String,
sleep_command: String,
}
impl Default for IdleConfig {
fn default() -> Self {
Self {
idle_timeout: 20,
dim_timeout: 60,
lock_timeout: 300,
sleep_timeout: 320,
..Default::default()
}
}
}
impl IdleConfig {
pub fn idle_timeout(&self) -> u64 {
self.idle_timeout
}
@@ -56,4 +66,12 @@ impl Config {
pub fn sleep_timeout_delta(&self) -> u64 {
self.sleep_timeout - self.lock_timeout_delta()
}
pub fn lock_command(&self) -> &str {
&self.lock_command
}
pub fn sleep_command(&self) -> &str {
&self.sleep_command
}
}