From b035cb625acce1e0aa977a2be84127b520c9eb7d Mon Sep 17 00:00:00 2001 From: Sebastian Moser Date: Mon, 5 May 2025 09:58:59 +0200 Subject: [PATCH] getting the instance to initialize in the mme-webview again --- build.rs | 2 ++ src/core/item.rs | 15 ++++++++++++++- src/platform/os/mod.rs | 24 ++++++++++-------------- src/platform/wasm/init.js | 10 +++++----- src/platform/wasm/mod.rs | 1 + 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/build.rs b/build.rs index 624b0b2..a682aa2 100644 --- a/build.rs +++ b/build.rs @@ -23,4 +23,6 @@ fn main() { //.expect("failed to start wasm build"); //to outdir (), using the nightly feature --out-dir to have the result there. By default I get a libhearts.rlib + + println!("cargo:rustc-link-arg=-zstack-size=0x500000"); } diff --git a/src/core/item.rs b/src/core/item.rs index 259871d..2821f80 100644 --- a/src/core/item.rs +++ b/src/core/item.rs @@ -133,14 +133,27 @@ impl Item<'_> { data.merge(new_data); trace!("item::merge new_data: {:?}", data); - if self.instance.we_are_namespace()? { + // handle the case of /self/* + if self.id().store_part() == "self" { + let rest_path = self.id().path.into_iter().skip(1).map(|v| v.to_owned()).collect::>().join("/"); + let id_for_store = self.instance.new_id("0".to_owned() + "/" + rest_path.as_str())?; + + let store_inner = self.instance.store.lock()?; + store_inner.set(id_for_store, data)?; + + + } else if self.instance.we_are_namespace()? { + let store_inner = self.instance.store.lock()?; store_inner.set(self.id(), data)?; + } else { + let namespace = self.id().namespace(); let mut connection = self.instance.get_connection_by_ns(namespace)?; let msg = MizeMessage::new_update_request(self.id(), data, connection.id); connection.send(msg)?; + } Ok(()) diff --git a/src/platform/os/mod.rs b/src/platform/os/mod.rs index aaf3c0f..bc81968 100644 --- a/src/platform/os/mod.rs +++ b/src/platform/os/mod.rs @@ -42,7 +42,7 @@ pub fn os_instance_init(instance: &mut Instance) -> MizeResult<()> { let config = config_from_file(config_file_path)?; debug!("env var MIZE_CONFIG_FILE present"); instance.set_blocking("0", config)?; - trace!("config after MIZE_CONFIG_FILE env var: {}", instance.get("0/config")?); + trace!("config after MIZE_CONFIG_FILE env var: {}", instance.get("self/config")?); } Err(var_err) => match var_err { VarError::NotPresent => { @@ -59,8 +59,8 @@ pub fn os_instance_init(instance: &mut Instance) -> MizeResult<()> { Ok(config_string) => { let config = data_from_string(config_string)?; debug!("env var MIZE_CONFIG present"); - instance.set_blocking("0/config", config)?; - trace!("config after MIZE_CONFIG env var: {}", instance.get("0/config")?); + instance.set_blocking("self/config", config)?; + trace!("config after MIZE_CONFIG env var: {}", instance.get("self/config")?); } Err(var_err) => match var_err { VarError::NotPresent => { @@ -75,7 +75,7 @@ pub fn os_instance_init(instance: &mut Instance) -> MizeResult<()> { ////// if a config.store_path is set, upgrade to the filestore there let mut test = instance.get("0")?.as_data_full()?; - let mut store_path = match instance.get("0/config/store_path")?.value_string() { + let mut store_path = match instance.get("self/config/store_path")?.value_string() { Ok(path) => { path }, @@ -88,9 +88,9 @@ pub fn os_instance_init(instance: &mut Instance) -> MizeResult<()> { let store_path = home_dir.to_owned() + "/.mize"; - instance.set_blocking("0/config/store_path", store_path.clone().into_item_data())?; + instance.set_blocking("self/config/store_path", store_path.clone().into_item_data())?; - let store_path = instance.get("0/config/store_path")?.value_string()?; + let store_path = instance.get("self/config/store_path")?.value_string()?; println!("store_path: {}", store_path); @@ -148,7 +148,7 @@ pub fn seconds_since_modification(path: &Path) -> MizeResult { pub fn get_module_hash(instance: &mut Instance, name: &str, mut options: ItemData) -> MizeResult<(String, String)> { - let mut selector_data = instance.get("0/config/selector")?.as_data_full()?; + let mut selector_data = instance.get("self/config/selector")?.as_data_full()?; // handle the case, when we want a module for not the system we are running on... let mut name_parts = name.split("."); @@ -230,7 +230,8 @@ fn download_module(instance: &mut Instance, store_path: &str, module_url: &str, pub fn fetch_module(instance: &mut Instance, module_name: &str) -> MizeResult { - if let Ok(module_path) = instance.get(format!("self/config/module_dir/{}", module_name))?.value_string() { + let module_name_with_slashes = module_name.replace(".", "/"); + if let Ok(module_path) = instance.get(format!("self/config/module_dir/{}", module_name_with_slashes))?.value_string() { // in case a dir is configured, which holds the modules output return Ok(module_path); } else { @@ -252,16 +253,11 @@ pub fn fetch_module(instance: &mut Instance, module_name: &str) -> MizeResult) -> MizeResult<()> { - let module_dir_from_config = instance.get(format!("self/config/module_dir/{}", module_name)); - let module_path = if path.is_some() { format!("{}/lib/libmize_module_{}.so", path.unwrap(), module_name) - } else if module_dir_from_config.is_ok() { - format!("{}/lib/libmize_module_{}.so", module_dir_from_config.unwrap().value_string()?, module_name) - } else { - format!("{}/lib/libmmize_module_{}.so", fetch_module(instance, module_name)?, module_name) + format!("{}/lib/libmize_module_{}.so", fetch_module(instance, module_name)?, module_name) }; let lib = unsafe { libloading::Library::new(module_path)? }; diff --git a/src/platform/wasm/init.js b/src/platform/wasm/init.js index 805a68e..1726094 100644 --- a/src/platform/wasm/init.js +++ b/src/platform/wasm/init.js @@ -1,6 +1,6 @@ -async function init_mize(config) { +export async function init_mize(config) { if ("mize" in window) { window.mize.set("self/config", config) @@ -8,10 +8,10 @@ async function init_mize(config) { } let config_str = ""; - if typeof config == "string" { + if (typeof config == "string") { config_str = config - } else if typeof config == "object" { + } else if (typeof config == "object") { config_str = JSON.stringify(config) } else { @@ -20,9 +20,9 @@ async function init_mize(config) { const { new_js_instance } = wasm_bindgen; - await wasm_bindgen() + await wasm_bindgen(config.module_dir.mize + "/mize_bg.wasm") - window.mize = await new_js_instance(config) + window.mize = await new_js_instance(config_str) window.mize.mod = {} window.mize.init() diff --git a/src/platform/wasm/mod.rs b/src/platform/wasm/mod.rs index e92d9a2..1b15376 100644 --- a/src/platform/wasm/mod.rs +++ b/src/platform/wasm/mod.rs @@ -82,6 +82,7 @@ pub struct JsItemHandle { #[wasm_bindgen] pub async fn new_js_instance(config_json_str: String) -> JsInstance { + console_log!("hooooooooooooooo"); panic::set_hook(Box::new(console_error_panic_hook::hook));