diff --git a/src/config.rs b/src/config.rs index 198066c..a046d96 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,5 @@ +use std::fs; + use serde::Deserialize; #[derive(Deserialize, Copy, Clone)] @@ -8,6 +10,21 @@ pub struct Config { #[derive(Deserialize)] #[serde(rename_all = "kebab-case")] -pub struct CompleteConfig { - pub seasonal_clock: Config, +struct CompleteConfig { + seasonal_clock: Config, +} + +pub fn get_config() -> Option { + let xdg_dirs = xdg::BaseDirectories::new().unwrap(); + let config_path = xdg_dirs + .place_config_file("seasonal-clock.toml") + .expect("cannot create configuration directory"); + let data: std::io::Result = fs::read_to_string(config_path); + + if let Ok(..) = data { + let complete_config: CompleteConfig = toml::from_str(&data.unwrap()).unwrap(); + Some(complete_config.seasonal_clock) + } else { + None + } } diff --git a/src/main.rs b/src/main.rs index 0f8126f..bff40d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,5 @@ extern crate smithay_client_toolkit as sctk; -use std::fs; - use calloop::{timer::Timer, EventLoop}; use sctk::reexports::client::protocol::{wl_shm, wl_surface}; use sctk::shm::AutoMemPool; @@ -11,23 +9,13 @@ use svg::node::element::path::Data as PathData; mod config; mod svg_clock; -use config::{CompleteConfig, Config}; +use config::{get_config, Config}; use svg_clock::{cache_hour_name_paths, gen_svg, svg_to_usvg}; sctk::default_environment!(SeasonalClock, desktop); fn main() { - let xdg_dirs = xdg::BaseDirectories::new().unwrap(); - let config_path = xdg_dirs - .place_config_file("seasonal-clock.toml") - .expect("cannot create configuration directory"); - let data: std::io::Result = fs::read_to_string(config_path); - let config: Option = if let Ok(..) = data { - let complete_config: CompleteConfig = toml::from_str(&data.unwrap()).unwrap(); - Some(complete_config.seasonal_clock) - } else { - None - }; + let config = get_config(); let (env, display, queue) = sctk::new_default_environment!(SeasonalClock, desktop) .expect("Unable to connect to a Wayland compositor");