Skip to content

Commit 4f17126

Browse files
committed
smol refactor & fixes
1 parent d8f6f41 commit 4f17126

File tree

14 files changed

+79
-40
lines changed

14 files changed

+79
-40
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# # published.
4545
# #
4646
# # We *could* pass through `--no-verify` so `cargo` doesn't build the crate before publishing,
47-
# # which is reasonable, since this job only runs after the Linux, Windows, and WASM builds
47+
# # which is reasonable, since this job only runs after the Linux, Windows, and Wasm builds
4848
# # have passed.
4949
# - name: "cargo release publish"
5050
# run: |-

src/homepage.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub fn add_to_homepage(label: &str, icon: Option<&str>, path: Option<&str>, widget: Option<&str>) {
2+
crate::Request::to(("our", "homepage", "homepage", "sys"))
3+
.body(
4+
serde_json::json!({
5+
"Add": {
6+
"label": label,
7+
"icon": icon,
8+
"path": path,
9+
"widget": widget
10+
}
11+
})
12+
.to_string(),
13+
)
14+
.send()
15+
.unwrap();
16+
}

src/http.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use thiserror::Error;
1515
// these types are a copy of the types used in http module of runtime.
1616
//
1717

18-
/// HTTP Request type that can be shared over WASM boundary to apps.
18+
/// HTTP Request type that can be shared over Wasm boundary to apps.
1919
/// This is the one you receive from the `http_server:distro:sys` service.
2020
#[derive(Debug, Serialize, Deserialize)]
2121
pub enum HttpServerRequest {
@@ -51,7 +51,7 @@ pub struct IncomingHttpRequest {
5151
// BODY is stored in the lazy_load_blob, as bytes
5252
}
5353

54-
/// HTTP Response type that can be shared over WASM boundary to apps.
54+
/// HTTP Response type that can be shared over Wasm boundary to apps.
5555
/// Respond to [`IncomingHttpRequest`] with this type.
5656
#[derive(Debug, Serialize, Deserialize)]
5757
pub struct HttpResponse {
@@ -287,7 +287,7 @@ impl IncomingHttpRequest {
287287
}
288288
}
289289

290-
/// Request type that can be shared over WASM boundary to apps.
290+
/// Request type that can be shared over Wasm boundary to apps.
291291
/// This is the one you send to the `http_client:distro:sys` service.
292292
#[derive(Debug, Serialize, Deserialize)]
293293
pub enum HttpClientAction {
@@ -306,7 +306,7 @@ pub enum HttpClientAction {
306306
},
307307
}
308308

309-
/// HTTP Request type that can be shared over WASM boundary to apps.
309+
/// HTTP Request type that can be shared over Wasm boundary to apps.
310310
/// This is the one you send to the `http_client:distro:sys` service.
311311
#[derive(Debug, Serialize, Deserialize)]
312312
pub struct OutgoingHttpRequest {
@@ -318,7 +318,7 @@ pub struct OutgoingHttpRequest {
318318
// TIMEOUT is stored in the message expect_response
319319
}
320320

321-
/// WebSocket Client Request type that can be shared over WASM boundary to apps.
321+
/// WebSocket Client Request type that can be shared over Wasm boundary to apps.
322322
/// This comes from an open websocket client connection in the `http_client:distro:sys` service.
323323
#[derive(Debug, Serialize, Deserialize)]
324324
pub enum HttpClientRequest {
@@ -331,7 +331,7 @@ pub enum HttpClientRequest {
331331
},
332332
}
333333

334-
/// HTTP Client Response type that can be shared over WASM boundary to apps.
334+
/// HTTP Client Response type that can be shared over Wasm boundary to apps.
335335
/// This is the one you receive from the `http_client:distro:sys` service.
336336
#[derive(Debug, Serialize, Deserialize)]
337337
pub enum HttpClientResponse {

src/lib.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! kinode process standard library for Rust compiled to WASM
1+
//! Kinode process standard library for Rust compiled to Wasm
22
//! Must be used in context of bindings generated by `kinode.wit`.
33
//!
44
//! This library provides a set of functions for interacting with the kinode
@@ -24,6 +24,11 @@ wit_bindgen::generate!({
2424

2525
/// Interact with the eth provider module.
2626
pub mod eth;
27+
/// Interact with the system homepage.
28+
///
29+
/// Note that your process must have the capability to message
30+
/// `homepage:homepage:sys` to use this module.
31+
pub mod homepage;
2732
/// Interact with the HTTP server and client modules.
2833
/// Contains types from the `http` crate to use as well.
2934
pub mod http;
@@ -43,27 +48,19 @@ pub mod timer;
4348
/// Interact with the virtual filesystem
4449
pub mod vfs;
4550

46-
// Types
47-
48-
mod package_id;
49-
pub use package_id::PackageId;
50-
mod process_id;
51-
pub use process_id::{ProcessId, ProcessIdParseError};
52-
mod address;
53-
pub use address::{Address, AddressParseError};
54-
mod request;
55-
pub use request::Request;
56-
mod response;
57-
pub use response::Response;
58-
mod message;
59-
use message::wit_message_to_message;
60-
pub use message::{Message, SendError, SendErrorKind};
61-
mod on_exit;
62-
pub use on_exit::OnExit;
63-
mod capability;
64-
pub use capability::Capability;
65-
mod lazy_load_blob;
66-
pub use lazy_load_blob::LazyLoadBlob;
51+
mod types;
52+
pub use types::{
53+
address::{Address, AddressParseError},
54+
capability::Capability,
55+
lazy_load_blob::LazyLoadBlob,
56+
message::wit_message_to_message,
57+
message::{Message, SendError, SendErrorKind},
58+
on_exit::OnExit,
59+
package_id::PackageId,
60+
process_id::{ProcessId, ProcessIdParseError},
61+
request::Request,
62+
response::Response,
63+
};
6764

6865
/// Implement the wit-bindgen specific code that the kernel uses to hook into
6966
/// a process. Write an `init(our: Address)` function and call it with this.
@@ -221,7 +218,7 @@ pub fn get_capability(our: &Address, params: &str) -> Option<Capability> {
221218
.cloned()
222219
}
223220

224-
/// get the next message body from the message queue, or propagate the error
221+
/// Get the next message body from the message queue, or propagate the error
225222
pub fn await_next_message_body() -> Result<Vec<u8>, SendError> {
226223
match await_message() {
227224
Ok(msg) => Ok(msg.body().to_vec()),
File renamed without changes.

src/message.rs renamed to src/types/message.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ pub enum Message {
2525
}
2626

2727
impl Message {
28-
pub fn is_request(&self) -> bool {
29-
match self {
30-
Message::Request { .. } => true,
31-
Message::Response { .. } => false,
32-
}
33-
}
3428
/// Get the source of a message.
3529
pub fn source(&self) -> &Address {
3630
match self {
@@ -63,14 +57,37 @@ impl Message {
6357
pub fn blob(&self) -> Option<LazyLoadBlob> {
6458
crate::get_blob()
6559
}
66-
6760
/// Get the capabilities of a message.
6861
pub fn capabilities(&self) -> &Vec<Capability> {
6962
match self {
7063
Message::Request { capabilities, .. } => capabilities,
7164
Message::Response { capabilities, .. } => capabilities,
7265
}
7366
}
67+
/// Check if a message is a request. Returns `false` if it's a response.
68+
pub fn is_request(&self) -> bool {
69+
match self {
70+
Message::Request { .. } => true,
71+
Message::Response { .. } => false,
72+
}
73+
}
74+
/// Check if a message was sent by a local process. Returns `false` if the
75+
/// source node is not our local node.
76+
pub fn is_local(&self, our: &Address) -> bool {
77+
match self {
78+
Message::Request { source, .. } => source == our,
79+
Message::Response { source, .. } => source == our,
80+
}
81+
}
82+
pub fn is_process<T>(&self, process: T) -> bool
83+
where
84+
ProcessId: PartialEq<T>,
85+
{
86+
match self {
87+
Message::Request { source, .. } => source.process == process,
88+
Message::Response { source, .. } => source.process == process,
89+
}
90+
}
7491
}
7592

7693
#[derive(Debug, Clone, Serialize, Deserialize)]

src/types/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub mod address;
2+
pub mod capability;
3+
pub mod lazy_load_blob;
4+
pub mod message;
5+
pub mod on_exit;
6+
pub mod package_id;
7+
pub mod process_id;
8+
pub mod request;
9+
pub mod response;
File renamed without changes.

0 commit comments

Comments
 (0)