Finished internal themes

This commit is contained in:
Mikayla Maki 2022-09-08 15:06:08 -07:00
parent 3171a0c312
commit d881320345
8 changed files with 17 additions and 7 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@
/crates/collab/static/styles.css
/vendor/bin
/assets/themes/*.json
/assets/themes/internal/*.json

View file

View file

@ -5220,7 +5220,7 @@ impl TestServer {
user_store: user_store.clone(),
project_store: project_store.clone(),
languages: Arc::new(LanguageRegistry::new(Task::ready(()))),
themes: ThemeRegistry::new((), cx.font_cache()),
themes: ThemeRegistry::new((), cx.font_cache(), false),
fs: fs.clone(),
build_window_options: Default::default,
initialize_workspace: |_, _, _| unimplemented!(),

View file

@ -10,20 +10,28 @@ pub struct ThemeRegistry {
themes: Mutex<HashMap<String, Arc<Theme>>>,
theme_data: Mutex<HashMap<String, Arc<Value>>>,
font_cache: Arc<FontCache>,
internal: bool,
}
impl ThemeRegistry {
pub fn new(source: impl AssetSource, font_cache: Arc<FontCache>) -> Arc<Self> {
pub fn new(source: impl AssetSource, font_cache: Arc<FontCache>, internal: bool) -> Arc<Self> {
Arc::new(Self {
assets: Box::new(source),
themes: Default::default(),
theme_data: Default::default(),
font_cache,
internal,
})
}
pub fn list(&self) -> impl Iterator<Item = ThemeMeta> + '_ {
self.assets.list("themes/").into_iter().filter_map(|path| {
let mut dirs = self.assets.list("themes/");
if self.internal {
dirs.extend(self.assets.list("themes/internal/"))
};
dirs.into_iter().filter_map(|path| {
let filename = path.strip_prefix("themes/")?;
let theme_name = filename.strip_suffix(".json")?;
self.get(theme_name).ok().map(|theme| theme.meta.clone())
@ -50,6 +58,7 @@ impl ThemeRegistry {
serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_slice(&theme_json))
})?;
// Reset name to be the file path, so that we can use it to access the stored themes
theme.meta.name = name.into();
let theme = Arc::new(theme);
self.themes.lock().insert(name.to_string(), theme.clone());

View file

@ -860,7 +860,7 @@ impl AppState {
let client = Client::new(http_client.clone());
let project_store = cx.add_model(|_| ProjectStore::new(project::Db::open_fake()));
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
let themes = ThemeRegistry::new((), cx.font_cache().clone());
let themes = ThemeRegistry::new((), cx.font_cache().clone(), false);
Arc::new(Self {
client,
themes,

View file

@ -85,7 +85,7 @@ fn main() {
}
});
let themes = ThemeRegistry::new(Assets, app.font_cache());
let themes = ThemeRegistry::new(Assets, app.font_cache(), internal);
let default_settings = Settings::defaults(Assets, &app.font_cache(), &themes);
let config_files = load_config_files(&app, fs.clone());

View file

@ -153,7 +153,7 @@ mod tests {
watch_settings_file(
default_settings.clone(),
source,
ThemeRegistry::new((), font_cache),
ThemeRegistry::new((), font_cache, false),
false,
cx,
)

View file

@ -1664,7 +1664,7 @@ mod tests {
.into(),
])
.unwrap();
let themes = ThemeRegistry::new(Assets, cx.font_cache().clone());
let themes = ThemeRegistry::new(Assets, cx.font_cache().clone(), false);
let settings = Settings::defaults(Assets, cx.font_cache(), &themes);
let mut has_default_theme = false;