BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / assets.rs

assets.rs

eba4ad94 History
assets.rs 1.2 KiB Download Raw
1use std::borrow::Cow;
2
3use gpui_kit::{AssetSource, Result, SharedString};
4
5macro_rules! symbols {
6 ($($name:literal),* $(,)?) => {
7 [$((concat!("symbols/", $name, ".svg"), include_bytes!(concat!("../assets/symbols/", $name, ".svg")) as &[u8])),*]
8 };
9}
10
11const SYMBOLS: [(&str, &[u8]); 15] = symbols![
12 "done",
13 "done_all",
14 "keyboard_return",
15 "schedule",
16 "close",
17 "reply",
18 "group",
19 "tag",
20 "image",
21 "check_circle",
22 "error",
23 "notifications",
24 "content_copy",
25 "attach_file",
26 "upload",
27];
28
29pub struct AppAssets;
30
31impl AssetSource for AppAssets {
32 fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
33 if let Some((_, bytes)) = SYMBOLS.iter().find(|(name, _)| *name == path) {
34 return Ok(Some(Cow::Borrowed(bytes)));
35 }
36 gpui_kit::assets::AllAssets.load(path)
37 }
38
39 fn list(&self, path: &str) -> Result<Vec<SharedString>> {
40 let mut names = gpui_kit::assets::AllAssets.list(path)?;
41 names.extend(
42 SYMBOLS
43 .iter()
44 .filter(|(name, _)| name.starts_with(path))
45 .map(|(name, _)| SharedString::from(*name)),
46 );
47 Ok(names)
48 }
49}