mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-17 00:13:17 +00:00
f31cf35da1
YOLO
35 lines
1014 B
Rust
35 lines
1014 B
Rust
use std::{cell::RefCell, sync::OnceLock};
|
|
|
|
use parking_lot::ReentrantMutex;
|
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
|
|
mod conv;
|
|
mod init;
|
|
mod screenshot;
|
|
mod util;
|
|
|
|
pub use conv::*;
|
|
pub use screenshot::ScreenshotPlugin;
|
|
pub(crate) use util::*;
|
|
|
|
static INITIALIZED: OnceLock<ReentrantMutex<RefCell<bool>>> = OnceLock::new();
|
|
|
|
/// The Studio application must only be initialized once (via `init` or
|
|
/// `startViewer`). Multiple calls to either of those functions will cause the
|
|
/// application to panic. This function can be used to query whether the app has
|
|
/// already been initialized.
|
|
#[wasm_bindgen(js_name = isInitialized)]
|
|
pub fn is_initialized() -> bool {
|
|
let wrapper = INITIALIZED.get_or_init(|| ReentrantMutex::new(RefCell::new(false)));
|
|
let guard = wrapper.lock();
|
|
let result = *guard.borrow();
|
|
|
|
result
|
|
}
|
|
|
|
pub(crate) fn initialize() {
|
|
let wrapper = INITIALIZED.get_or_init(|| ReentrantMutex::new(RefCell::new(false)));
|
|
let guard = wrapper.lock();
|
|
*guard.borrow_mut() = true;
|
|
}
|