Load JSON themes (#6893)

This PR changes the theme loading to use the JSON themes bundled with
the binary rather then the Rust theme definitions.

### Performance

I profiled this using `cargo run --release` to see what the speed
differences would be now that we're deserializing JSON:

**Before:** `ThemeRegistry::load_user_themes` took 16.656666ms
**After:** `ThemeRegistry::load_user_themes` took 18.784875ms

It's slightly slower, but not by much. There is probably some work we
could do here to bring down the theme loading time in general.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2024-01-27 16:03:04 -05:00
committed by GitHub
parent f7fc4ffbe5
commit 5f1dcb76fe
7 changed files with 133 additions and 48 deletions
+11 -7
View File
@@ -33,7 +33,7 @@ pub use styles::*;
pub use themes::*;
pub use user_theme::*;
use gpui::{AppContext, Hsla, SharedString};
use gpui::{AppContext, AssetSource, Hsla, SharedString};
use serde::Deserialize;
#[derive(Debug, PartialEq, Clone, Copy, Deserialize)]
@@ -51,7 +51,6 @@ impl Appearance {
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum LoadThemes {
/// Only load the base theme.
///
@@ -59,15 +58,20 @@ pub enum LoadThemes {
JustBase,
/// Load all of the built-in themes.
All,
All(Box<dyn AssetSource>),
}
pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) {
cx.set_global(ThemeRegistry::default());
match themes_to_load {
LoadThemes::JustBase => (),
LoadThemes::All => cx.global_mut::<ThemeRegistry>().load_user_themes(),
let (assets, load_user_themes) = match themes_to_load {
LoadThemes::JustBase => (Box::new(()) as Box<dyn AssetSource>, false),
LoadThemes::All(assets) => (assets, true),
};
cx.set_global(ThemeRegistry::new(assets));
if load_user_themes {
cx.global_mut::<ThemeRegistry>().load_user_themes();
}
ThemeSettings::register(cx);
let mut prev_buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;