Inline some clones to make code more readable, add config, implement dimming -> locking -> sleeping into idle daemon, fix waiting on network thread, implement run menu with application launching and math evaluation,
This commit is contained in:
59
src/config.rs
Normal file
59
src/config.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> Config {
|
||||
fs::read_to_string("jmb-bar.conf")
|
||||
.ok()
|
||||
.map(|s| toml::from_str::<Config>(&s).ok())
|
||||
.flatten()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn idle_timeout(&self) -> u64 {
|
||||
self.idle_timeout
|
||||
}
|
||||
|
||||
pub fn dim_timeout(&self) -> u64 {
|
||||
self.dim_timeout
|
||||
}
|
||||
|
||||
pub fn lock_timeout(&self) -> u64 {
|
||||
self.lock_timeout
|
||||
}
|
||||
|
||||
pub fn sleep_timeout(&self) -> u64 {
|
||||
self.sleep_timeout
|
||||
}
|
||||
|
||||
pub fn dim_timeout_delta(&self) -> u64 {
|
||||
self.dim_timeout - self.idle_timeout
|
||||
}
|
||||
|
||||
pub fn lock_timeout_delta(&self) -> u64 {
|
||||
self.lock_timeout - self.dim_timeout_delta()
|
||||
}
|
||||
|
||||
pub fn sleep_timeout_delta(&self) -> u64 {
|
||||
self.sleep_timeout - self.lock_timeout_delta()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user