Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T02:37:29.938Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

assets.rs

66 lines · 2.1 KB · rust
1// This crate was essentially pulled out verbatim from main `zed` crate to avoid having to run RustEmbed macro whenever zed has to be rebuilt. It saves a second or two on an incremental build.
2
3use anyhow::Context as _;
4use gpui::{App, AssetSource, Result, SharedString};
5use rust_embed::RustEmbed;
6
7#[derive(RustEmbed)]
8#[folder = "../../assets"]
9#[include = "fonts/**/*"]
10#[include = "icons/**/*"]
11#[include = "images/**/*"]
12#[include = "themes/**/*"]
13#[exclude = "themes/src/*"]
14#[include = "sounds/**/*"]
15#[include = "prompts/**/*"]
16#[include = "*.md"]
17#[exclude = "*.DS_Store"]
18pub struct Assets;
19
20impl AssetSource for Assets {
21    fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
22        Self::get(path)
23            .map(|f| Some(f.data))
24            .with_context(|| format!("loading asset at path {path:?}"))
25    }
26
27    fn list(&self, path: &str) -> Result<Vec<SharedString>> {
28        Ok(Self::iter()
29            .filter_map(|p| {
30                if p.starts_with(path) {
31                    Some(p.into())
32                } else {
33                    None
34                }
35            })
36            .collect())
37    }
38}
39
40impl Assets {
41    /// Populate the [`TextSystem`] of the given [`AppContext`] with all `.ttf` fonts in the `fonts` directory.
42    pub fn load_fonts(&self, cx: &App) -> anyhow::Result<()> {
43        let font_paths = self.list("fonts")?;
44        let mut embedded_fonts = Vec::new();
45        for font_path in font_paths {
46            if font_path.ends_with(".ttf") {
47                let font_bytes = cx
48                    .asset_source()
49                    .load(&font_path)?
50                    .expect("Assets should never return None");
51                embedded_fonts.push(font_bytes);
52            }
53        }
54
55        cx.text_system().add_fonts(embedded_fonts)
56    }
57
58    pub fn load_test_fonts(&self, cx: &App) {
59        cx.text_system()
60            .add_fonts(vec![
61                self.load("fonts/lilex/Lilex-Regular.ttf").unwrap().unwrap(),
62            ])
63            .unwrap()
64    }
65}
66
Served at tenant.openagents/omega Member data and write actions are omitted.