diff --git a/Cargo.lock b/Cargo.lock index 3c36bbf..1b4e108 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1047,7 +1047,7 @@ dependencies = [ [[package]] name = "usdpl-front" -version = "0.5.0" +version = "0.6.0" dependencies = [ "console_error_panic_hook", "hex", @@ -1063,7 +1063,7 @@ dependencies = [ [[package]] name = "usdpl-rs" -version = "0.1.0" +version = "0.6.0" [[package]] name = "utf-8" diff --git a/usdpl-front/Cargo.toml b/usdpl-front/Cargo.toml index 37d1de5..00656fd 100644 --- a/usdpl-front/Cargo.toml +++ b/usdpl-front/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "usdpl-front" -version = "0.6.0" +version = "0.6.1" authors = ["NGnius (Graham) "] edition = "2021" license = "GPL-3.0-only" diff --git a/usdpl-front/src/lib.rs b/usdpl-front/src/lib.rs index 053dea8..1ed9f10 100644 --- a/usdpl-front/src/lib.rs +++ b/usdpl-front/src/lib.rs @@ -19,6 +19,8 @@ use usdpl_core::{socket::Packet, RemoteCall}; static mut CTX: UsdplContext = UsdplContext { port: 31337, id: 1, #[cfg(feature = "encrypt")] key: Vec::new() }; +static mut CACHE: Option> = None; + #[cfg(feature = "encrypt")] fn encryption_key() -> Vec { hex::decode(obfstr::obfstr!(env!("USDPL_ENCRYPTION_KEY"))).unwrap() @@ -69,6 +71,10 @@ pub fn init_usdpl(port: u16) { key: encryption_key(), }; } + + unsafe { + CACHE = Some(std::collections::HashMap::new()); + } } /// Get the targeted plugin framework, or "any" if unknown @@ -77,6 +83,22 @@ pub fn target() -> String { usdpl_core::api::Platform::current().to_string() } +/// Get the targeted plugin framework, or "any" if unknown +#[wasm_bindgen] +pub fn set_value(key: String, value: JsValue) -> JsValue { + unsafe { + CACHE.as_mut().unwrap().insert(key, value).unwrap_or(JsValue::NULL) + } +} + +/// Get the targeted plugin framework, or "any" if unknown +#[wasm_bindgen] +pub fn get_value(key: String) -> JsValue { + unsafe { + CACHE.as_ref().unwrap().get(&key).map(|x| x.to_owned()).unwrap_or(JsValue::UNDEFINED) + } +} + /// Call a function on the back-end. /// Returns null (None) if this fails for any reason. #[wasm_bindgen]