diff --git a/kinode/packages/homepage/api/homepage:sys-v0.wit b/kinode/packages/homepage/api/homepage:sys-v0.wit index 34e7e8612..7eace9c0b 100644 --- a/kinode/packages/homepage/api/homepage:sys-v0.wit +++ b/kinode/packages/homepage/api/homepage:sys-v0.wit @@ -7,6 +7,9 @@ interface homepage { /// the icon is a base64 encoded image. add(add-request), remove, + /// ONLY settings:settings:sys may call this request + /// (this is checked in-code) + set-stylesheet(string), } record add-request { diff --git a/kinode/packages/homepage/homepage/src/lib.rs b/kinode/packages/homepage/homepage/src/lib.rs index 238aa45ee..3909939bf 100644 --- a/kinode/packages/homepage/homepage/src/lib.rs +++ b/kinode/packages/homepage/homepage/src/lib.rs @@ -74,18 +74,43 @@ fn init(our: Address) { ) .expect("failed to bind to /our.js"); + // the base version gets written over on-bootstrap, so we look for + // the persisted (user-customized) version first. + // if it doesn't exist, we use the bootstrapped version and save it here. + let stylesheet = kinode_process_lib::vfs::File { + path: "/homepage:sys/pkg/persisted-kinode.css".to_string(), + timeout: 5, + } + .read() + .unwrap_or_else(|_| { + kinode_process_lib::vfs::File { + path: "/homepage:sys/pkg/kinode.css".to_string(), + timeout: 5, + } + .read() + .expect("failed to get kinode.css") + }); + + // save the stylesheet to the persisted file + kinode_process_lib::vfs::File { + path: "/homepage:sys/pkg/persisted-kinode.css".to_string(), + timeout: 5, + } + .write(&stylesheet) + .expect("failed to write to /persisted-kinode.css"); + bind_http_static_path( "/kinode.css", - true, + false, // kinode.css is not auth'd so that apps on subdomains can use it too! false, Some("text/css".to_string()), - include_str!("../../pkg/kinode.css").into(), + stylesheet, ) .expect("failed to bind /kinode.css"); bind_http_static_path( "/kinode.svg", - true, + false, // kinode.svg is not auth'd so that apps on subdomains can use it too! false, Some("image/svg+xml".to_string()), include_str!("../../pkg/kinode.svg").into(), @@ -94,7 +119,7 @@ fn init(our: Address) { bind_http_static_path( "/bird-orange.svg", - true, + false, // bird-orange.svg is not auth'd so that apps on subdomains can use it too! false, Some("image/svg+xml".to_string()), include_str!("../../pkg/bird-orange.svg").into(), @@ -103,7 +128,7 @@ fn init(our: Address) { bind_http_static_path( "/bird-plain.svg", - true, + false, // bird-plain.svg is not auth'd so that apps on subdomains can use it too! false, Some("image/svg+xml".to_string()), include_str!("../../pkg/bird-plain.svg").into(), @@ -173,6 +198,28 @@ fn init(our: Address) { HomepageRequest::Remove => { app_data.remove(&message.source().process.to_string()); } + HomepageRequest::SetStylesheet(new_stylesheet_string) => { + // ONLY settings:settings:sys may call this request + if message.source().process != "settings:settings:sys" { + continue; + } + kinode_process_lib::vfs::File { + path: "/homepage:sys/pkg/persisted-kinode.css".to_string(), + timeout: 5, + } + .write(new_stylesheet_string.as_bytes()) + .expect("failed to write to /persisted-kinode.css"); + // re-bind + bind_http_static_path( + "/kinode.css", + false, // kinode.css is not auth'd so that apps on subdomains can use it too! + false, + Some("text/css".to_string()), + new_stylesheet_string.into(), + ) + .expect("failed to bind /kinode.css"); + println!("updated kinode.css!"); + } } } else if let Ok(req) = serde_json::from_slice::(message.body()) { match req { diff --git a/kinode/packages/settings/pkg/manifest.json b/kinode/packages/settings/pkg/manifest.json index c6c457d35..67f8735df 100644 --- a/kinode/packages/settings/pkg/manifest.json +++ b/kinode/packages/settings/pkg/manifest.json @@ -16,7 +16,13 @@ "http_server:distro:sys", "kernel:distro:sys", "net:distro:sys", - "vfs:distro:sys" + "vfs:distro:sys", + { + "process": "vfs:distro:sys", + "params": { + "root": true + } + } ], "grant_capabilities": [ "eth:distro:sys", diff --git a/kinode/packages/settings/pkg/ui/index.html b/kinode/packages/settings/pkg/ui/index.html index 21afb6269..ab1de0562 100644 --- a/kinode/packages/settings/pkg/ui/index.html +++ b/kinode/packages/settings/pkg/ui/index.html @@ -6,14 +6,22 @@ +