2023-10-04 08:51:47 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
|
|
use anyhow::{anyhow, Result};
|
2023-11-06 18:46:10 +00:00
|
|
|
use gpui::{AssetSource, SharedString};
|
2023-10-04 08:51:47 +00:00
|
|
|
use rust_embed::RustEmbed;
|
|
|
|
|
|
|
|
#[derive(RustEmbed)]
|
|
|
|
#[folder = "../../assets"]
|
|
|
|
#[include = "fonts/**/*"]
|
|
|
|
#[include = "icons/**/*"]
|
|
|
|
#[include = "themes/**/*"]
|
|
|
|
#[include = "sounds/**/*"]
|
|
|
|
#[include = "*.md"]
|
|
|
|
#[exclude = "*.DS_Store"]
|
|
|
|
pub struct Assets;
|
|
|
|
|
|
|
|
impl AssetSource for Assets {
|
2024-05-30 01:06:45 +00:00
|
|
|
fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
|
2023-10-24 15:47:41 +00:00
|
|
|
Self::get(path)
|
2023-10-04 08:51:47 +00:00
|
|
|
.map(|f| f.data)
|
|
|
|
.ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
|
2024-05-30 01:06:45 +00:00
|
|
|
.map(|data| Some(data))
|
2023-10-04 08:51:47 +00:00
|
|
|
}
|
|
|
|
|
2023-10-24 15:47:41 +00:00
|
|
|
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
2023-10-04 08:51:47 +00:00
|
|
|
Ok(Self::iter()
|
2023-10-24 15:47:41 +00:00
|
|
|
.filter(|p| p.starts_with(path))
|
2023-10-04 08:51:47 +00:00
|
|
|
.map(SharedString::from)
|
|
|
|
.collect())
|
|
|
|
}
|
|
|
|
}
|