51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use anyhow::Context;
|
|
use gpui::{AssetSource, Result, SharedString};
|
|
use rust_embed::RustEmbed;
|
|
|
|
#[derive(RustEmbed)]
|
|
#[folder = "../../assets"]
|
|
#[include = "fonts/**/*"]
|
|
#[include = "brand/**/*"]
|
|
#[include = "icons/**/*"]
|
|
#[exclude = "*.DS_Store"]
|
|
pub struct Assets;
|
|
|
|
/// Coop's bundled assets, with the GPUI Kit component icon bundle (Lucide) as
|
|
/// the fallback so `IconName` SVGs resolve alongside coop's own files.
|
|
pub struct CombinedAssets;
|
|
|
|
impl AssetSource for CombinedAssets {
|
|
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
|
|
if let Some(data) = Assets.load(path)? {
|
|
return Ok(Some(data));
|
|
}
|
|
gpui_kit::assets::Assets.load(path)
|
|
}
|
|
|
|
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
|
let mut paths = Assets.list(path)?;
|
|
paths.extend(gpui_kit::assets::Assets.list(path)?);
|
|
Ok(paths)
|
|
}
|
|
}
|
|
|
|
impl AssetSource for Assets {
|
|
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
|
|
Self::get(path)
|
|
.map(|f| Some(f.data))
|
|
.with_context(|| format!("loading 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())
|
|
}
|
|
}
|