BlueGit

ict rusty-teams

Files

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

assets.rs

assets.rs 1.4 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]); 24] = 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 "download",
28 "folder_open",
29 "refresh",
30 "code",
31 "link",
32 "format_list_bulleted",
33 "format_list_numbered",
34 "format_quote",
35 "mood",
36];
37
38pub struct AppAssets;
39
40impl AssetSource for AppAssets {
41 fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
42 if let Some((_, bytes)) = SYMBOLS.iter().find(|(name, _)| *name == path) {
43 return Ok(Some(Cow::Borrowed(bytes)));
44 }
45 gpui_kit::assets::AllAssets.load(path)
46 }
47
48 fn list(&self, path: &str) -> Result<Vec<SharedString>> {
49 let mut names = gpui_kit::assets::AllAssets.list(path)?;
50 names.extend(
51 SYMBOLS
52 .iter()
53 .filter(|(name, _)| name.starts_with(path))
54 .map(|(name, _)| SharedString::from(*name)),
55 );
56 Ok(names)
57 }
58}