1pub use std::path::Path;
2pub use std::path::PathBuf;
3pub use std::sync::Mutex;
4pub use std::sync::OnceLock;
5
6pub static MUTABLE_CONFIG: OnceLock<Mutex<Config>> = OnceLock::new();
7
8#[derive(Debug)]
9pub struct Config {
10 pub pdf_images: PathBuf,
11 pub index_txt: PathBuf,
12 pub bookmarks_txt: PathBuf,
13}
14
15pub fn initialize_mutable_config(dir: String) {
16 let expanded_dir = shellexpand::tilde(&dir);
17 let pdf_images = PathBuf::from(expanded_dir.into_owned());
18 let index_txt = pdf_images.clone().join("index.txt");
19 let bookmarks_txt = pdf_images.clone().join("bookmarks.txt");
20
21 MUTABLE_CONFIG
22 .set(Mutex::new(Config {
23 pdf_images: pdf_images,
24 index_txt: index_txt,
25 bookmarks_txt: bookmarks_txt,
26 }))
27 .expect("Mutable config already initialized");
28}
29
30pub fn update_index_txt_path(dir: String) {
31 let expanded_dir = shellexpand::tilde(&dir);
32 let pdf_images = PathBuf::from(expanded_dir.into_owned());
33 let index_txt = pdf_images.clone().join("index.txt");
34 let bookmarks_txt = pdf_images.clone().join("bookmarks.txt");
35 let config_lock = MUTABLE_CONFIG.get().expect("Config not initialized");
36 let mut config = config_lock.lock().unwrap(); config.pdf_images = pdf_images;
38 config.index_txt = index_txt;
39 config.bookmarks_txt = bookmarks_txt;
40}