//! Actions only the user interface handles, such as closing one of its
//! windows. They never leave the user interface's thread.
use std::cell::RefCell;
use egui::ViewportId;
thread_local! {
static QUEUE: RefCell<Vec<LocalAction>> = const { RefCell::new(Vec::new()) };
}
#[derive(Debug)]
pub(crate) enum LocalAction {
CloseWindow(ViewportId),
OpenGitConfigWindow,
}
impl LocalAction {
/// Queues the action for the next frame.
pub(crate) fn enqueue(self) {
QUEUE.with(|queue| queue.borrow_mut().push(self));
}
/// The queued actions, oldest first.
pub(crate) fn take_all() -> Vec<Self> {
QUEUE.with(|queue| std::mem::take(&mut *queue.borrow_mut()))
}
}