Skip to main content

selene_core/
lib.rs

1use std::{path::PathBuf, sync::LazyLock};
2
3use directories::BaseDirs;
4
5use crate::container::ContainerFormat;
6
7pub const PROGRAM_NAME: &str = "selene";
8
9pub mod codec;
10pub mod config;
11pub mod container;
12pub mod database;
13pub mod errors;
14mod ffmpeg;
15pub mod library;
16pub mod media_container;
17pub mod utils;
18
19pub const SUPPORTED_CONTAINERS: [ContainerFormat; 4] = [
20    ContainerFormat::Flac,
21    ContainerFormat::Mp3,
22    ContainerFormat::Ogg,
23    ContainerFormat::Wav,
24];
25
26static BASE_DIRS: LazyLock<Option<BaseDirs>> = LazyLock::new(BaseDirs::new);
27
28/// Returns the users `base_dirs`
29///
30/// # Panics
31///
32/// Panics if the internal `BASE_DIRS` static is [`None`]. This can only happen if the home directory is not found
33pub fn base_dirs() -> &'static BaseDirs {
34    BASE_DIRS.as_ref().unwrap()
35}
36
37#[must_use]
38pub fn config_dir() -> PathBuf {
39    base_dirs().config_dir().join(PROGRAM_NAME)
40}
41
42#[must_use]
43pub fn data_dir() -> PathBuf {
44    base_dirs().data_dir().join(PROGRAM_NAME)
45}
46
47#[must_use]
48pub fn cache_dir() -> PathBuf {
49    base_dirs().cache_dir().join(PROGRAM_NAME)
50}
51
52#[must_use]
53pub fn runtime_dir() -> PathBuf {
54    base_dirs().runtime_dir().unwrap().join(PROGRAM_NAME)
55}