Add support for loading user themes (#7027)
This PR adds support for loading user themes in Zed. Themes are loaded from the `themes` directory under the Zed config: `~/.config/zed/themes`. This directory should contain JSON files containing a `ThemeFamilyContent`. Here's an example of the general structure of a theme family file: ```jsonc { "name": "Vitesse", "author": "Anthony Fu", "themes": [ { "name": "Vitesse Dark Soft", "appearance": "dark", "style": { "border": "#252525", // ... } } ] } ``` Themes placed in this directory will be loaded and available in the theme selector. Release Notes: - Added support for loading user themes from `~/.config/zed/themes`.
This commit is contained in:
parent
5f4dd36a1a
commit
9cb5a84b8d
9 changed files with 131 additions and 38 deletions
|
@ -38,7 +38,7 @@ use std::{
|
|||
},
|
||||
thread,
|
||||
};
|
||||
use theme::ActiveTheme;
|
||||
use theme::{ActiveTheme, ThemeRegistry, ThemeSettings};
|
||||
use util::{
|
||||
async_maybe,
|
||||
channel::{parse_zed_link, AppCommitSha, ReleaseChannel, RELEASE_CHANNEL},
|
||||
|
@ -164,6 +164,36 @@ fn main() {
|
|||
);
|
||||
assistant::init(cx);
|
||||
|
||||
// TODO: Should we be loading the themes in a different spot?
|
||||
cx.spawn({
|
||||
let fs = fs.clone();
|
||||
|cx| async move {
|
||||
if let Some(theme_registry) =
|
||||
cx.update(|cx| ThemeRegistry::global(cx).clone()).log_err()
|
||||
{
|
||||
if let Some(()) = theme_registry
|
||||
.load_user_themes(&paths::THEMES_DIR.clone(), fs)
|
||||
.await
|
||||
.log_err()
|
||||
{
|
||||
cx.update(|cx| {
|
||||
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
||||
|
||||
if let Some(requested_theme) = theme_settings.requested_theme.clone() {
|
||||
if let Some(_theme) =
|
||||
theme_settings.switch_theme(&requested_theme, cx)
|
||||
{
|
||||
ThemeSettings::override_global(theme_settings, cx);
|
||||
}
|
||||
}
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
cx.spawn(|_| watch_languages(fs.clone(), languages.clone()))
|
||||
.detach();
|
||||
watch_file_types(fs.clone(), cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue