From b6ea375485083860094a904b7a6c7d97fa42b8f8 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 10 Jul 2020 22:35:30 +0530 Subject: follow XDG_DATA_DIR spec for app data --- src/utils.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs index 55900b0..ab7e7ef 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,6 @@ use cursive::theme::{BaseColor, Color}; +use directories::ProjectDirs; +use std::path::{Path, PathBuf}; pub struct AppConfig { pub true_chr: char, @@ -30,3 +32,13 @@ pub fn load_configuration_file() -> AppConfig { future_color: Color::Light(BaseColor::Black), }; } + +pub fn data_file() -> PathBuf { + if let Some(proj_dirs) = ProjectDirs::from("rs", "nerdypepper", "dijo") { + let mut data_file = PathBuf::from(proj_dirs.data_dir()); + data_file.push("habit_record.json"); + return data_file; + } else { + panic!("Invalid home directory!") + }; +} -- cgit v1.2.3