feat: support assets
This commit is contained in:
0
assets/.keep
Normal file
0
assets/.keep
Normal file
@@ -17,3 +17,4 @@ keyring-search.workspace = true
|
|||||||
keyring.workspace = true
|
keyring.workspace = true
|
||||||
|
|
||||||
client = { version = "0.1.0", path = "../client" }
|
client = { version = "0.1.0", path = "../client" }
|
||||||
|
rust-embed = "8.5.0"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use client::NostrClient;
|
use client::NostrClient;
|
||||||
use components::theme::{Theme, ThemeColor, ThemeMode};
|
use components::theme::{Theme, ThemeColor, ThemeMode};
|
||||||
use gpui::*;
|
use gpui::*;
|
||||||
|
use http_client::anyhow;
|
||||||
use state::AppState;
|
use state::AppState;
|
||||||
use views::app::AppView;
|
use views::app::AppView;
|
||||||
|
|
||||||
@@ -8,6 +9,30 @@ pub mod state;
|
|||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod views;
|
pub mod views;
|
||||||
|
|
||||||
|
#[derive(rust_embed::RustEmbed)]
|
||||||
|
#[folder = "../../assets"]
|
||||||
|
struct Assets;
|
||||||
|
|
||||||
|
impl AssetSource for Assets {
|
||||||
|
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
|
||||||
|
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<Vec<SharedString>> {
|
||||||
|
Ok(Self::iter()
|
||||||
|
.filter_map(|p| {
|
||||||
|
if p.starts_with(path) {
|
||||||
|
Some(p.into())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// Initialize nostr client
|
// Initialize nostr client
|
||||||
@@ -15,7 +40,7 @@ async fn main() {
|
|||||||
// Initializ app state
|
// Initializ app state
|
||||||
let app_state = AppState::new();
|
let app_state = AppState::new();
|
||||||
|
|
||||||
App::new().run(move |cx| {
|
App::new().with_assets(Assets).run(move |cx| {
|
||||||
// Initialize components
|
// Initialize components
|
||||||
components::init(cx);
|
components::init(cx);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user