diff --git a/assets/.keep b/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/crates/ui/Cargo.toml b/crates/ui/Cargo.toml index 5796762..a71470f 100644 --- a/crates/ui/Cargo.toml +++ b/crates/ui/Cargo.toml @@ -17,3 +17,4 @@ keyring-search.workspace = true keyring.workspace = true client = { version = "0.1.0", path = "../client" } +rust-embed = "8.5.0" diff --git a/crates/ui/src/main.rs b/crates/ui/src/main.rs index 33e98e0..7943f29 100644 --- a/crates/ui/src/main.rs +++ b/crates/ui/src/main.rs @@ -1,6 +1,7 @@ use client::NostrClient; use components::theme::{Theme, ThemeColor, ThemeMode}; use gpui::*; +use http_client::anyhow; use state::AppState; use views::app::AppView; @@ -8,6 +9,30 @@ pub mod state; pub mod utils; pub mod views; +#[derive(rust_embed::RustEmbed)] +#[folder = "../../assets"] +struct Assets; + +impl AssetSource for Assets { + fn load(&self, path: &str) -> Result>> { + Self::get(path) + .map(|f| Some(f.data)) + .ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path)) + } + + fn list(&self, path: &str) -> Result> { + Ok(Self::iter() + .filter_map(|p| { + if p.starts_with(path) { + Some(p.into()) + } else { + None + } + }) + .collect()) + } +} + #[tokio::main] async fn main() { // Initialize nostr client @@ -15,7 +40,7 @@ async fn main() { // Initializ app state let app_state = AppState::new(); - App::new().run(move |cx| { + App::new().with_assets(Assets).run(move |cx| { // Initialize components components::init(cx);