Skip to content

Commit

Permalink
config_parser: Use user home
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed Apr 20, 2024
1 parent 93ef5c1 commit a723530
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/utils/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@ use toml::Table;

use crate::{utils::macros::ErrorLevel, write_log_to_file, ERROR};

pub static mut CONFIG_STRING: &str = "~/reset/ReSet.toml";
pub static mut CONFIG_STRING: Lazy<String> = Lazy::new(|| {
let base = directories_next::ProjectDirs::from("org", "Xetibo", "ReSet");
if let Some(base) = base {
return base
.config_dir()
.join("ReSet.toml")
.to_str()
.unwrap()
.to_string();
} else {
ERROR!("Failed to get user home", ErrorLevel::Critical);
}
String::from("")
});
#[allow(clippy::declare_interior_mutable_const)]
pub const CONFIG: Lazy<Table> = Lazy::new(parse_config);

pub fn parse_config() -> Table {
unsafe {
let config_file = fs::File::open(CONFIG_STRING);
let config_file = fs::File::open(CONFIG_STRING.as_str());
if config_file.is_err() {
ERROR!("Could not write config file", ErrorLevel::Recoverable);
return Table::new();
Expand Down

0 comments on commit a723530

Please sign in to comment.