diff --git a/src/app.rs b/src/app.rs index 2c38191..461aeee 100644 --- a/src/app.rs +++ b/src/app.rs @@ -14,12 +14,7 @@ use ratatui::prelude::{Widget}; use ratatui::style::{Color, Style}; use ratatui::text::{Line, Span, Text}; use crate::config::types::ApplicationConfig; -use crate::constants::{APP_CONFIG_DIR, APP_DATA_DIR}; - -lazy_static! { - static ref APP_CONIFG_FILE_PATH: PathBuf = APP_CONFIG_DIR.clone() - .join("config.ini"); -} +use crate::constants::{APP_CONFIG_DIR, APP_CONIFG_FILE_PATH, APP_DATA_DIR}; pub(crate) struct App { running: bool, @@ -33,8 +28,8 @@ impl App { let app_conf = if APP_CONIFG_FILE_PATH.exists() { ApplicationConfig::from_file(&APP_CONIFG_FILE_PATH) } else { ApplicationConfig::new() }; + Self::initialize(); let db_conn = Self::establish_db_connection(app_conf.clone()); - Self::initialize(&db_conn); App { running: true, events: EventHandler::new(Duration::from_millis(app_conf.basic_config.tick_rate)), @@ -43,7 +38,7 @@ impl App { } } - fn initialize(db_conn: &SqliteConnection) { + fn initialize() { if !APP_CONFIG_DIR.exists() { std::fs::create_dir_all(APP_CONFIG_DIR.as_path()).unwrap(); } diff --git a/src/config/mod.rs b/src/config/mod.rs index aaaeea4..aa3d599 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,7 +1,7 @@ use std::path::{PathBuf}; use ini::Ini; use crate::config::types::{ApplicationConfig, BasicConfig}; -use crate::constants::APP_CONFIG_DIR; +use crate::constants::{APP_CONFIG_DIR, APP_CONIFG_FILE_PATH}; pub mod types; @@ -19,12 +19,14 @@ impl ApplicationConfig { } pub fn new() -> Self { - Self { + let conf = Self { basic_config: BasicConfig { - db_path: APP_CONFIG_DIR.clone().to_str().unwrap().to_string(), + db_path: APP_CONFIG_DIR.clone().join("games.db").to_str().unwrap().to_string(), tick_rate: 250 } - } + }; + conf.clone().write_to_file(APP_CONIFG_FILE_PATH.to_path_buf()); + conf } pub fn write_to_file(self, path: PathBuf) { diff --git a/src/constants.rs b/src/constants.rs index d870d24..2dd2da1 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -9,4 +9,6 @@ lazy_static!( .join(APP_DIR_NAME); pub static ref APP_DATA_DIR: PathBuf = BASE_DIRS.data_dir().to_path_buf() .join(APP_DIR_NAME); + pub static ref APP_CONIFG_FILE_PATH: PathBuf = APP_CONFIG_DIR.clone() + .join("config.ini"); ); \ No newline at end of file