BlueGit

ict rusty-teams

Files

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

assets.rs

refactor(app): extract app-base crate
metis Daniel Däschle · pushed by metis · 6 weeks ago
16e522c2 History
assets.rs 1.7 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!("../../app/assets/symbols/", $name, ".svg")) as &[u8])),*]
8 };
9}
10
11const SYMBOLS: [(&str, &[u8]); 46] = symbols![
12 "done",
13 "done_all",
14 "keyboard_return",
15 "schedule",
16 "schedule_send",
17 "event",
18 "wb_sunny",
19 "work",
20 "close",
21 "reply",
22 "group",
23 "tag",
24 "image",
25 "check_circle",
26 "error",
27 "notifications",
28 "content_copy",
29 "attach_file",
30 "upload",
31 "download",
32 "folder_open",
33 "refresh",
34 "code",
35 "link",
36 "format_list_bulleted",
37 "format_list_numbered",
38 "format_quote",
39 "mood",
40 "status_dot",
41 "status_dnd",
42 "status_away",
43 "status_ring",
44 "zoom_in",
45 "zoom_out",
46 "rotate_right",
47 "forward",
48 "open_in_new",
49 "chevron_left",
50 "chevron_right",
51 "fullscreen",
52 "spinner_track",
53 "spinner_arc",
54 "shield",
55 "call",
56 "call_missed",
57 "videocam",
58];
59
60pub struct AppAssets;
61
62impl AssetSource for AppAssets {
63 fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
64 if let Some((_, bytes)) = SYMBOLS.iter().find(|(name, _)| *name == path) {
65 return Ok(Some(Cow::Borrowed(bytes)));
66 }
67 gpui_kit::assets::AllAssets.load(path)
68 }
69
70 fn list(&self, path: &str) -> Result<Vec<SharedString>> {
71 let mut names = gpui_kit::assets::AllAssets.list(path)?;
72 names.extend(
73 SYMBOLS
74 .iter()
75 .filter(|(name, _)| name.starts_with(path))
76 .map(|(name, _)| SharedString::from(*name)),
77 );
78 Ok(names)
79 }
80}