| 1 | use std::borrow::Cow; |
| 2 | |
| 3 | use gpui_kit::{AssetSource, Result, SharedString}; |
| 4 | |
| 5 | macro_rules! symbols { |
| 6 | ($($name:literal),* $(,)?) => { |
| 7 | [$((concat!("symbols/", $name, ".svg"), include_bytes!(concat!("../assets/symbols/", $name, ".svg")) as &[u8])),*] |
| 8 | }; |
| 9 | } |
| 10 | |
| 11 | const SYMBOLS: [(&str, &[u8]); 23] = 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 | ]; |
| 36 | |
| 37 | pub struct AppAssets; |
| 38 | |
| 39 | impl AssetSource for AppAssets { |
| 40 | fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> { |
| 41 | if let Some((_, bytes)) = SYMBOLS.iter().find(|(name, _)| *name == path) { |
| 42 | return Ok(Some(Cow::Borrowed(bytes))); |
| 43 | } |
| 44 | gpui_kit::assets::AllAssets.load(path) |
| 45 | } |
| 46 | |
| 47 | fn list(&self, path: &str) -> Result<Vec<SharedString>> { |
| 48 | let mut names = gpui_kit::assets::AllAssets.list(path)?; |
| 49 | names.extend( |
| 50 | SYMBOLS |
| 51 | .iter() |
| 52 | .filter(|(name, _)| name.starts_with(path)) |
| 53 | .map(|(name, _)| SharedString::from(*name)), |
| 54 | ); |
| 55 | Ok(names) |
| 56 | } |
| 57 | } |