Move conf struct to config.rs and impl Default
Signed-off-by: Marko Korhonen <marko.korhonen@reekynet.com>
This commit is contained in:
parent
6404ae7463
commit
04e23c6144
2 changed files with 24 additions and 22 deletions
|
@ -1,16 +1,26 @@
|
||||||
|
extern crate xdg;
|
||||||
|
|
||||||
use super::fs;
|
use super::fs;
|
||||||
use super::Config;
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use xdg::BaseDirectories;
|
use xdg::BaseDirectories;
|
||||||
|
|
||||||
extern crate xdg;
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct Config {
|
||||||
|
pub resume_file: PathBuf,
|
||||||
|
pub idle_level: i32,
|
||||||
|
pub dim_speed: u64,
|
||||||
|
pub resume_speed: u64,
|
||||||
|
}
|
||||||
|
|
||||||
fn default_config() -> Config {
|
impl Default for Config {
|
||||||
Config {
|
fn default() -> Self {
|
||||||
resume_file: PathBuf::from("/tmp/lqsd-resume"),
|
Self {
|
||||||
idle_level: 0,
|
resume_file: PathBuf::from("/tmp/lqsd-resume"),
|
||||||
dim_speed: 50,
|
idle_level: 0,
|
||||||
resume_speed: 25,
|
dim_speed: 50,
|
||||||
|
resume_speed: 25,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,11 +39,11 @@ pub fn load_xdg() -> Config {
|
||||||
"{} does not exist, writing default configuration",
|
"{} does not exist, writing default configuration",
|
||||||
path.display()
|
path.display()
|
||||||
);
|
);
|
||||||
match fs::write(&path, toml::to_string(&default_config()).unwrap()) {
|
match fs::write(&path, toml::to_string(&Config::default()).unwrap()) {
|
||||||
Ok(()) => println!("Default config saved to {}", path.display()),
|
Ok(()) => println!("Default config saved to {}", path.display()),
|
||||||
Err(err) => eprintln!("Failed to write default config: {}", err),
|
Err(err) => eprintln!("Failed to write default config: {}", err),
|
||||||
};
|
};
|
||||||
default_config()
|
Config::default()
|
||||||
} else {
|
} else {
|
||||||
let toml = fs::read(&path).unwrap();
|
let toml = fs::read(&path).unwrap();
|
||||||
let config: Config = toml::from_str(&toml).unwrap();
|
let config: Config = toml::from_str(&toml).unwrap();
|
||||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -1,21 +1,13 @@
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
|
||||||
mod cli;
|
use config::Config;
|
||||||
mod config;
|
|
||||||
mod fs;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
mod cli;
|
||||||
pub struct Config {
|
mod config;
|
||||||
resume_file: PathBuf,
|
mod fs;
|
||||||
idle_level: i32,
|
|
||||||
dim_speed: u64,
|
|
||||||
resume_speed: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn transition(w_brightness: i32, speed: time::Duration) {
|
fn transition(w_brightness: i32, speed: time::Duration) {
|
||||||
let c_brightness = get_brightness();
|
let c_brightness = get_brightness();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue