pub(crate) mod action;
pub(crate) mod collections;
mod files;
pub(crate) mod git;
pub(crate) mod migration;
pub(crate) mod store;
mod worker;
pub(crate) use gled_model::{asset, asset_id, collection};
pub(crate) use worker::start_thread;
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use std::{
path::PathBuf,
sync::atomic::{AtomicBool, AtomicUsize, Ordering::Relaxed},
};
use strum::Display;
pub(crate) static STORAGE_DIR: Lazy<PathBuf> = Lazy::new(crate::paths::storage_dir);
static STORAGE_VERSION_FILE: Lazy<PathBuf> = Lazy::new(|| STORAGE_DIR.join("version"));
static WORKING: AtomicBool = AtomicBool::new(true);
static ERROR: Lazy<Mutex<Option<String>>> = Lazy::new(|| Mutex::new(None));
static LOADING: AtomicLoading = AtomicLoading::new(Loading::No);
static BRANCHES: Lazy<Mutex<Option<Branches>>> = Lazy::new(|| Mutex::new(None));
static STAGED_FILES: AtomicUsize = AtomicUsize::new(0);
static STORAGE_VERSION_WRITTEN: AtomicBool = AtomicBool::new(false);
#[derive(Debug, Clone)]
pub(crate) struct Branches {
pub(crate) available: Vec<String>,
pub(crate) current: String,
}
#[derive(Display, Default, PartialEq, Eq)]
#[atomic_enum::atomic_enum]
pub(crate) enum Loading {
#[default]
#[strum(serialize = "Idling")]
No,
#[strum(serialize = "Nuking storage")]
Nuking,
#[strum(serialize = "Loading git repository")]
GitRepository,
#[strum(serialize = "Loading git branches")]
GitBranches,
#[strum(serialize = "Loading current git branch")]
GitBranch,
#[strum(serialize = "Converting old assets")]
Migrating,
#[strum(serialize = "Loading animations")]
Animations,
#[strum(serialize = "Loading curves")]
Curves,
#[strum(serialize = "Loading fixture definitions")]
FixtureDefinitions,
#[strum(serialize = "Loading output devices")]
OutputDevices,
#[strum(serialize = "Loading MIDI controllers")]
MidiControllers,
#[strum(serialize = "Loading palettes")]
Palettes,
#[strum(serialize = "Loading projects")]
Projects,
#[strum(serialize = "Loading scenes")]
Scenes,
#[strum(serialize = "Synchronizing")]
Synchronizing,
}
impl Loading {
pub(crate) fn set(self) {
LOADING.store(self, Relaxed);
}
}
pub(crate) fn working() -> bool {
WORKING.load(Relaxed)
}
pub(crate) fn staged_files() -> usize {
STAGED_FILES.load(Relaxed)
}
pub(crate) fn loading() -> Loading {
LOADING.load(Relaxed)
}
pub(crate) fn is_loading() -> bool {
loading() != Loading::No
}
pub(crate) fn error() -> Option<String> {
ERROR.lock().clone()
}
pub(crate) fn branches() -> Option<Branches> {
BRANCHES.lock().clone()
}