From 6a17af0c144120408d09c606ab589acd5ddcb466 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Wed, 25 Dec 2024 18:44:35 -0500 Subject: [PATCH 1/3] add a lil clock, fix app store widget background bg --- .../app-store/app-store/src/http_api.rs | 1 - kinode/packages/homepage/homepage/src/lib.rs | 132 +++++++++++++++++- 2 files changed, 131 insertions(+), 2 deletions(-) diff --git a/kinode/packages/app-store/app-store/src/http_api.rs b/kinode/packages/app-store/app-store/src/http_api.rs index b70d0291..8a7c9dc4 100644 --- a/kinode/packages/app-store/app-store/src/http_api.rs +++ b/kinode/packages/app-store/app-store/src/http_api.rs @@ -88,7 +88,6 @@ fn make_widget() -> String { body { overflow: hidden; - background: transparent; } #latest-apps { diff --git a/kinode/packages/homepage/homepage/src/lib.rs b/kinode/packages/homepage/homepage/src/lib.rs index bd45bc9a..9a0d66ce 100644 --- a/kinode/packages/homepage/homepage/src/lib.rs +++ b/kinode/packages/homepage/homepage/src/lib.rs @@ -163,6 +163,8 @@ fn init(our: Address) { .bind_http_path("/order", http_config) .expect("failed to bind /order"); + kinode_process_lib::homepage::add_to_homepage("Clock", None, None, Some(&make_clock_widget())); + // load persisted app order let mut persisted_app_order = kinode_process_lib::get_typed_state(|bytes| serde_json::from_slice(bytes)) @@ -194,7 +196,12 @@ fn init(our: Address) { )), ), "/version" => { - if app_data.len() >= 4 { + // hacky way to ensure that the homepage has populated itself before + // loading in after boot + if app_data.len() >= 4 + && app_data.values().filter(|app| app.widget.is_some()).count() + >= 3 + { ( server::HttpResponse::new(http::StatusCode::OK), Some(LazyLoadBlob::new( @@ -381,3 +388,126 @@ fn version_from_cargo_toml() -> String { .trim_matches('"') .to_string() } + +fn make_clock_widget() -> String { + return format!( + r#" + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + +"# + ); +} From 745405ed6e37f157c5c5060b4b812ae4aaf4d4f5 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Thu, 26 Dec 2024 02:09:17 -0500 Subject: [PATCH 2/3] get rid of useless cloning --- .../kns-indexer/kns-indexer/src/lib.rs | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/kinode/packages/kns-indexer/kns-indexer/src/lib.rs b/kinode/packages/kns-indexer/kns-indexer/src/lib.rs index 958493af..9c6fcefa 100644 --- a/kinode/packages/kns-indexer/kns-indexer/src/lib.rs +++ b/kinode/packages/kns-indexer/kns-indexer/src/lib.rs @@ -109,15 +109,11 @@ impl State { impl From for WitKnsUpdate { fn from(k: net::KnsUpdate) -> Self { WitKnsUpdate { - name: k.name.clone(), - public_key: k.public_key.clone(), - ips: k.ips.clone(), - ports: k - .ports - .iter() - .map(|(k, v)| (k.clone(), v.clone())) - .collect::>(), - routers: k.routers.clone(), + name: k.name, + public_key: k.public_key, + ips: k.ips, + ports: k.ports.into_iter().map(|(k, v)| (k, v)).collect::>(), + routers: k.routers, } } } @@ -125,11 +121,11 @@ impl From for WitKnsUpdate { impl From for net::KnsUpdate { fn from(k: WitKnsUpdate) -> Self { net::KnsUpdate { - name: k.name.clone(), - public_key: k.public_key.clone(), - ips: k.ips.clone(), + name: k.name, + public_key: k.public_key, + ips: k.ips, ports: BTreeMap::from_iter(k.ports), - routers: k.routers.clone(), + routers: k.routers, } } } @@ -138,19 +134,15 @@ impl From for WitState { fn from(s: State) -> Self { let contract_address: [u8; 20] = s.contract_address.into(); WitState { - chain_id: s.chain_id.clone(), + chain_id: s.chain_id, contract_address: contract_address.to_vec(), - names: s - .names - .iter() - .map(|(k, v)| (k.clone(), v.clone())) - .collect::>(), + names: s.names.into_iter().map(|(k, v)| (k, v)).collect::>(), nodes: s .nodes - .iter() - .map(|(k, v)| (k.clone(), v.clone().into())) + .into_iter() + .map(|(k, v)| (k, v.into())) .collect::>(), - last_block: s.last_checkpoint_block.clone(), + last_block: s.last_checkpoint_block, } } } From d007eb6c882bb77aeee3012051908b1b1e17d82f Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Thu, 26 Dec 2024 13:17:21 -0500 Subject: [PATCH 3/3] add set_on_exit behavior properly to kernel --- kinode/src/kernel/mod.rs | 8 ++++++ kinode/src/kernel/standard_host_v1.rs | 39 ++++++++++++++++++++++++--- kinode/src/state.rs | 5 +--- lib/src/kernel.rs | 2 ++ 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/kinode/src/kernel/mod.rs b/kinode/src/kernel/mod.rs index c47624e6..85f4f90c 100644 --- a/kinode/src/kernel/mod.rs +++ b/kinode/src/kernel/mod.rs @@ -369,6 +369,14 @@ async fn handle_kernel_request( .expect("event loop: fatal: sender died"); None } + t::KernelCommand::SetOnExit { target, on_exit } => { + if let Some(process) = process_map.get_mut(&target) { + process.on_exit = on_exit; + } + // persist state because it changed + persist_state(&send_to_loop, process_map).await; + None + } // // send 'run' message to a process that's already been initialized // diff --git a/kinode/src/kernel/standard_host_v1.rs b/kinode/src/kernel/standard_host_v1.rs index 5846bca6..76a858d5 100644 --- a/kinode/src/kernel/standard_host_v1.rs +++ b/kinode/src/kernel/standard_host_v1.rs @@ -497,11 +497,42 @@ impl StandardHost for process::ProcessWasiV1 { // process management: // - /// TODO critical: move to kernel logic to enable persistence of choice made here async fn set_on_exit(&mut self, on_exit: wit::OnExit) -> Result<()> { - self.process.metadata.on_exit = t::OnExit::de_wit_v1(on_exit); - print_debug(&self.process, "set new on-exit behavior").await; - Ok(()) + let on_exit = t::OnExit::de_wit_v1(on_exit); + self.process.metadata.on_exit = on_exit.clone(); + match self + .process + .send_request_v1( + Some(t::Address { + node: self.process.metadata.our.node.clone(), + process: KERNEL_PROCESS_ID.clone(), + }), + wit::Address { + node: self.process.metadata.our.node.clone(), + process: KERNEL_PROCESS_ID.en_wit_v1(), + }, + wit::Request { + inherit: false, + expects_response: None, + body: serde_json::to_vec(&t::KernelCommand::SetOnExit { + target: self.process.metadata.our.process.clone(), + on_exit, + }) + .unwrap(), + metadata: None, + capabilities: vec![], + }, + None, + None, + ) + .await + { + Ok(_) => { + print_debug(&self.process, "set new on-exit behavior").await; + Ok(()) + } + Err(e) => Err(e), + } } async fn get_on_exit(&mut self) -> Result { diff --git a/kinode/src/state.rs b/kinode/src/state.rs index 77385a03..eff83457 100644 --- a/kinode/src/state.rs +++ b/kinode/src/state.rs @@ -75,10 +75,7 @@ pub async fn load_state( } } - // bootstrap the distro processes into the node. TODO: - // once we manage userspace sys packages onchain, stop - // doing this and allow node operator to manually or auto-update - // all their own userspace packages. + // bootstrap the distro processes into the node bootstrap( &our_name, keypair, diff --git a/lib/src/kernel.rs b/lib/src/kernel.rs index c62a3a7a..094899ba 100644 --- a/lib/src/kernel.rs +++ b/lib/src/kernel.rs @@ -429,6 +429,8 @@ pub enum KernelCommand { target: ProcessId, capabilities: Vec, }, + /// Set the on-exit behavior for a process. + SetOnExit { target: ProcessId, on_exit: OnExit }, /// Tell the kernel to run a process that has already been installed. /// TODO: in the future, this command could be extended to allow for /// resource provision.