gled-core 2.31.2

The engine of gled without a user interface: inputs, timing, rendering, Art-Net/DMX output and storage
Documentation
use gled_protocol::bytes::SharedBytes;
use kanal::{Receiver, Sender, bounded};
use std::{path::PathBuf, sync::OnceLock};
use uuid::Uuid;

static SENDER: OnceLock<Sender<StorageAction>> = OnceLock::new();

pub(crate) fn init() -> Receiver<StorageAction> {
    let (tx, rx) = bounded(16);
    SENDER.set(tx).expect("Could not set ACTION_SENDER");
    rx
}

#[derive(Debug)]
pub(crate) enum StorageAction {
    /// Nuke the storage folder and restart from scratch
    Nuke,
    /// Restart the storage system
    Restart,
    /// Stop the storage system
    Stop,
    LoadBranches,
    LoadAssets,
    SwitchBranch(String),
    SaveAsset {
        dir_name: &'static str,
        uuid: Uuid,
        json: String,
    },
    DeleteAsset {
        dir_name: &'static str,
        uuid: Uuid,
    },
    /// Writes a picture an interface chose into the repository, at `path`
    /// there; the engine checked that it names a picture inside it.
    SavePicture {
        path: PathBuf,
        bytes: SharedBytes,
    },
    Pull,
    Push,
    CountStagedFiles,
    Commit {
        message: String,
    },
}

impl StorageAction {
    pub(crate) fn enqueue(self) {
        SENDER
            .get()
            .expect("Could not get ACTION_SENDER")
            .send(self)
            .expect("Could not send action");
    }
}