find data dir properly

This commit is contained in:
2023-04-28 22:34:17 -07:00
parent c5dcc2e50a
commit b761d3b493
5 changed files with 90 additions and 36 deletions

View File

@ -75,35 +75,32 @@ pub fn set_auto_launch(is_configured: bool) -> Result<(), SetupError> {
let auto = AutoLaunchBuilder::new()
.set_app_name("Creddy")
.set_app_path(&path)
.build().expect("Failed to build");
.build()?;
let is_enabled = auto.is_enabled()?;
if is_configured && !is_enabled {
auto.enable().expect("Failed to enable");
auto.enable()?;
}
else if !is_configured && is_enabled {
auto.disable().expect("Failed to disable");
auto.disable()?;
}
Ok(())
}
pub fn get_or_create_db_path() -> PathBuf {
pub fn get_or_create_db_path() -> Result<PathBuf, DataDirError> {
if cfg!(debug_assertions) {
return PathBuf::from("./creddy.db");
return Ok(PathBuf::from("./creddy.db"));
}
let mut parent = std::env::var("HOME")
.map(|h| {
let mut p = PathBuf::from(h);
p.push(".config");
p
})
.unwrap_or(PathBuf::from("."));
let mut path = dirs::data_dir()
.ok_or(DataDirError::NotFound)?;
parent.push("creddy.db");
parent
std::fs::create_dir_all(&path)?;
path.push("creddy.db");
Ok(path)
}