1#![allow(dead_code, unused_variables)]
2
3use crate::theme::Theme;
4use ::theme as legacy_theme;
5use element_ext::ElementExt;
6use gpui2::{serde_json, vec2f, view, Element, RectF, ViewContext, WindowBounds};
7use legacy_theme::ThemeSettings;
8use log::LevelFilter;
9use settings::{default_settings, SettingsStore};
10use simplelog::SimpleLogger;
11
12mod collab_panel;
13mod components;
14mod element_ext;
15mod modules;
16mod theme;
17mod workspace;
18
19gpui2::actions! {
20 storybook,
21 [ToggleInspector]
22}
23
24fn main() {
25 SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
26
27 gpui2::App::new(Assets).unwrap().run(|cx| {
28 let mut store = SettingsStore::default();
29 store
30 .set_default_settings(default_settings().as_ref(), cx)
31 .unwrap();
32 cx.set_global(store);
33 legacy_theme::init(Assets, cx);
34 // load_embedded_fonts(cx.platform().as_ref());
35
36 cx.add_window(
37 gpui2::WindowOptions {
38 bounds: WindowBounds::Fixed(RectF::new(vec2f(0., 0.), vec2f(1600., 900.))),
39 center: true,
40 ..Default::default()
41 },
42 |cx| {
43 view(|cx| {
44 // cx.enable_inspector();
45 storybook(&mut ViewContext::new(cx))
46 })
47 },
48 );
49 cx.platform().activate(true);
50 });
51}
52
53fn storybook<V: 'static>(cx: &mut ViewContext<V>) -> impl Element<V> {
54 workspace().themed(current_theme(cx))
55}
56
57// Nathan: During the transition to gpui2, we will include the base theme on the legacy Theme struct.
58fn current_theme<V: 'static>(cx: &mut ViewContext<V>) -> Theme {
59 settings::get::<ThemeSettings>(cx)
60 .theme
61 .deserialized_base_theme
62 .lock()
63 .get_or_insert_with(|| {
64 let theme: Theme =
65 serde_json::from_value(settings::get::<ThemeSettings>(cx).theme.base_theme.clone())
66 .unwrap();
67 Box::new(theme)
68 })
69 .downcast_ref::<Theme>()
70 .unwrap()
71 .clone()
72}
73
74use anyhow::{anyhow, Result};
75use gpui2::AssetSource;
76use rust_embed::RustEmbed;
77use workspace::workspace;
78
79#[derive(RustEmbed)]
80#[folder = "../../assets"]
81#[include = "themes/**/*"]
82#[include = "fonts/**/*"]
83#[include = "icons/**/*"]
84#[exclude = "*.DS_Store"]
85pub struct Assets;
86
87impl AssetSource for Assets {
88 fn load(&self, path: &str) -> Result<std::borrow::Cow<[u8]>> {
89 Self::get(path)
90 .map(|f| f.data)
91 .ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
92 }
93
94 fn list(&self, path: &str) -> Vec<std::borrow::Cow<'static, str>> {
95 Self::iter().filter(|p| p.starts_with(path)).collect()
96 }
97}
98
99// fn load_embedded_fonts(platform: &dyn gpui2::Platform) {
100// let font_paths = Assets.list("fonts");
101// let mut embedded_fonts = Vec::new();
102// for font_path in &font_paths {
103// if font_path.ends_with(".ttf") {
104// let font_path = &*font_path;
105// let font_bytes = Assets.load(font_path).unwrap().to_vec();
106// embedded_fonts.push(Arc::from(font_bytes));
107// }
108// }
109// platform.fonts().add_fonts(&embedded_fonts).unwrap();
110// }