mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-22 16:11:38 +03:00
across the grlobe
This commit is contained in:
parent
c44be19ba6
commit
8115cce388
37
Cargo.lock
generated
37
Cargo.lock
generated
@ -1117,6 +1117,19 @@ dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blog"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"kinode_process_lib 0.9.0",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"url",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blst"
|
||||
version = "0.3.12"
|
||||
@ -2517,6 +2530,17 @@ version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
|
||||
[[package]]
|
||||
name = "globe"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"kinode_process_lib 0.9.0",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"url",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "group"
|
||||
version = "0.13.0"
|
||||
@ -6723,19 +6747,6 @@ dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "widget"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"kinode_process_lib 0.9.0",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"url",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wiggle"
|
||||
version = "19.0.2"
|
||||
|
@ -18,7 +18,7 @@ members = [
|
||||
"kinode/packages/app_store/download", "kinode/packages/app_store/install", "kinode/packages/app_store/uninstall",
|
||||
"kinode/packages/chess/chess",
|
||||
"kinode/packages/homepage/homepage",
|
||||
"kinode/packages/kino_updates/widget",
|
||||
"kinode/packages/kino_updates/blog", "kinode/packages/kino_updates/globe",
|
||||
"kinode/packages/kns_indexer/kns_indexer", "kinode/packages/kns_indexer/get_block", "kinode/packages/kns_indexer/state",
|
||||
"kinode/packages/settings/settings",
|
||||
"kinode/packages/terminal/terminal",
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "widget"
|
||||
name = "blog"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
@ -32,7 +32,7 @@ fn init(_our: Address) {
|
||||
.body(
|
||||
serde_json::json!({
|
||||
"Add": {
|
||||
"label": "KinoUpdates",
|
||||
"label": "Updates from kinode.org",
|
||||
"widget": create_widget(fetch_most_recent_blog_posts(12)),
|
||||
}
|
||||
})
|
20
kinode/packages/kino_updates/globe/Cargo.toml
Normal file
20
kinode/packages/kino_updates/globe/Cargo.toml
Normal file
@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "globe"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
simulation-mode = []
|
||||
|
||||
[dependencies]
|
||||
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", branch = "develop" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
url = "2.5.0"
|
||||
wit-bindgen = "0.24.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.component]
|
||||
package = "kinode:process"
|
91
kinode/packages/kino_updates/globe/src/lib.rs
Normal file
91
kinode/packages/kino_updates/globe/src/lib.rs
Normal file
@ -0,0 +1,91 @@
|
||||
use kinode_process_lib::{call_init, http, println, Address, Request};
|
||||
|
||||
wit_bindgen::generate!({
|
||||
path: "target/wit",
|
||||
world: "process-v0",
|
||||
});
|
||||
|
||||
call_init!(init);
|
||||
fn init(_our: Address) {
|
||||
// fetch our location with HTTP client
|
||||
let location_json = loop {
|
||||
match http::send_request_await_response(
|
||||
http::Method::GET,
|
||||
url::Url::parse("https://ipapi.co/json/").unwrap(),
|
||||
Some(std::collections::HashMap::from([(
|
||||
"User-Agent".to_string(),
|
||||
"ipapi.co/#rust-v1.5".to_string(),
|
||||
)])),
|
||||
60,
|
||||
vec![],
|
||||
) {
|
||||
Ok(response) => match serde_json::from_slice::<serde_json::Value>(response.body()) {
|
||||
Ok(location) => {
|
||||
if location.get("latitude").is_some() && location.get("longitude").is_some() {
|
||||
break location;
|
||||
} else {
|
||||
println!("Failed to parse location: {location:?}");
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Failed to parse location: {e:?}");
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Failed to fetch location: {e:?}");
|
||||
}
|
||||
};
|
||||
std::thread::sleep(std::time::Duration::from_secs(5));
|
||||
};
|
||||
|
||||
// add ourselves to the homepage
|
||||
Request::to(("our", "homepage", "homepage", "sys"))
|
||||
.body(
|
||||
serde_json::json!({
|
||||
"Add": {
|
||||
"label": "Globe",
|
||||
"widget": create_widget(location_json),
|
||||
}
|
||||
})
|
||||
.to_string(),
|
||||
)
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn create_widget(location_json: serde_json::Value) -> String {
|
||||
return format!(
|
||||
r#"<html>
|
||||
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script src="//unpkg.com/globe.gl"></script>
|
||||
</head>
|
||||
|
||||
<body style="margin: 0; width: 100%; height: 100%;">
|
||||
<div id="globe" style="margin: 0; width: 100%; height: 100%;"></div>
|
||||
<script>
|
||||
// Get user's location from IP address and display that point
|
||||
const data = {};
|
||||
console.log(data);
|
||||
const gData = [{{
|
||||
lat: data.latitude,
|
||||
lng: data.longitude,
|
||||
size: 0.3,
|
||||
color: 'red'
|
||||
}}];
|
||||
|
||||
Globe()
|
||||
.globeImageUrl('//unpkg.com/three-globe/example/img/earth-blue-marble.jpg')
|
||||
.pointsData(gData)
|
||||
.pointAltitude('size')
|
||||
.pointColor('color')
|
||||
.pointOfView({{ lat: data.latitude, lng: data.longitude, altitude: 2 }}, 1000)
|
||||
(document.getElementById('globe'));
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>"#,
|
||||
location_json
|
||||
);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kino_updates",
|
||||
"description": "A simple widget that serves latest blog posts from kinode.org",
|
||||
"name": "Kinode Updates",
|
||||
"description": "A simple widget that serves latest blog posts and more from kinode.org",
|
||||
"image": "https://kinode.org/static/media/kinode.a60d538cb0ae88c56b07.png",
|
||||
"properties": {
|
||||
"package_name": "kino_updates",
|
||||
|
@ -1,7 +1,7 @@
|
||||
[
|
||||
{
|
||||
"process_name": "widget",
|
||||
"process_wasm_path": "/widget.wasm",
|
||||
"process_name": "blog",
|
||||
"process_wasm_path": "/blog.wasm",
|
||||
"on_exit": "Restart",
|
||||
"request_networking": false,
|
||||
"request_capabilities": [
|
||||
@ -13,5 +13,19 @@
|
||||
"timer:distro:sys"
|
||||
],
|
||||
"public": false
|
||||
},
|
||||
{
|
||||
"process_name": "globe",
|
||||
"process_wasm_path": "/globe.wasm",
|
||||
"on_exit": "None",
|
||||
"request_networking": false,
|
||||
"request_capabilities": [
|
||||
"homepage:homepage:sys",
|
||||
"http_client:distro:sys"
|
||||
],
|
||||
"grant_capabilities": [
|
||||
"http_client:distro:sys"
|
||||
],
|
||||
"public": false
|
||||
}
|
||||
]
|
@ -574,11 +574,6 @@ pub async fn kernel(
|
||||
let mut non_rebooted_processes: HashSet<t::ProcessId> = HashSet::new();
|
||||
|
||||
for (process_id, persisted) in &process_map {
|
||||
// filter out OnExit::None processes from process_map
|
||||
if persisted.on_exit.is_none() {
|
||||
non_rebooted_processes.insert(process_id.clone());
|
||||
continue;
|
||||
}
|
||||
// runtime extensions will have a bytes_handle of "", because they have no
|
||||
// WASM code saved in filesystem.
|
||||
if persisted.wasm_bytes_handle.is_empty() {
|
||||
@ -897,6 +892,10 @@ pub async fn kernel(
|
||||
&engine,
|
||||
&home_directory_path,
|
||||
).await {
|
||||
// drain process map of processes with OnExit::None
|
||||
process_map.retain(|_, persisted| !persisted.on_exit.is_none());
|
||||
// persist state
|
||||
persist_state(&send_to_loop, &process_map).await;
|
||||
// shut down the node
|
||||
return Ok(());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user