glossa_cli/
static_data.rs

1use std::path::{Path, PathBuf};
2
3use glossa::sys::new_once_lock;
4
5pub fn config_dir() -> &'static Path {
6  new_once_lock!(V: PathBuf);
7
8  V.get_or_init(|| {
9    let proj_dir = || match directories::ProjectDirs::from("me", "tmoe", "glossa")
10      .map(|d| d.config_local_dir().into())
11    {
12      Some(v) => v,
13      _ => std::env::temp_dir().join("me.tmoe.glossa"),
14    };
15
16    match crate::envs::static_glossa_cfg_dir() {
17      Some(v) => v.into(),
18      _ => proj_dir(),
19    }
20  })
21}
22
23pub fn bincode_dir() -> Option<&'static Path> {
24  new_once_lock!(P: Option<PathBuf>);
25
26  P.get_or_init(|| {
27    let dir = config_dir();
28    dir
29      .exists()
30      .then(|| dir.join("bincode"))
31      .filter(|x| x.exists())
32  })
33  .as_deref()
34}