Sorted themes correctly

This commit is contained in:
Mikayla Maki
2022-09-08 14:11:48 -07:00
parent a1889ad236
commit bdf655d757
5 changed files with 34 additions and 23 deletions
+7 -1
View File
@@ -15,7 +15,7 @@ pub use theme_registry::*;
#[derive(Deserialize, Default)]
pub struct Theme {
#[serde(default)]
pub name: String,
pub meta: ThemeMeta,
pub workspace: Workspace,
pub context_menu: ContextMenu,
pub chat_panel: ChatPanel,
@@ -34,6 +34,12 @@ pub struct Theme {
pub terminal: TerminalStyle,
}
#[derive(Deserialize, Default, Clone)]
pub struct ThemeMeta {
pub name: String,
pub is_light: bool,
}
#[derive(Deserialize, Default)]
pub struct Workspace {
pub background: Color,
+4 -4
View File
@@ -1,4 +1,4 @@
use crate::Theme;
use crate::{Theme, ThemeMeta};
use anyhow::{Context, Result};
use gpui::{fonts, AssetSource, FontCache};
use parking_lot::Mutex;
@@ -22,11 +22,11 @@ impl ThemeRegistry {
})
}
pub fn list(&self) -> impl Iterator<Item = String> {
pub fn list(&self) -> impl Iterator<Item = ThemeMeta> + '_ {
self.assets.list("themes/").into_iter().filter_map(|path| {
let filename = path.strip_prefix("themes/")?;
let theme_name = filename.strip_suffix(".json")?;
Some(theme_name.to_string())
self.get(theme_name).ok().map(|theme| theme.meta.clone())
})
}
@@ -50,7 +50,7 @@ impl ThemeRegistry {
serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_slice(&theme_json))
})?;
theme.name = name.into();
theme.meta.name = name.into();
let theme = Arc::new(theme);
self.themes.lock().insert(name.to_string(), theme.clone());
Ok(theme)