Add support for specifying both light and dark themes in settings.json
(#7404)
This PR adds support for configuring both a light and dark theme in `settings.json`. In addition to accepting just a theme name, the `theme` field now also accepts an object in the following form: ```jsonc { "theme": { "mode": "system", "light": "One Light", "dark": "One Dark" } } ``` Both `light` and `dark` are required, and indicate which theme should be used when the system is in light mode and dark mode, respectively. The `mode` field is optional and indicates which theme should be used: - `"system"` - Use the theme that corresponds to the system's appearance. - `"light"` - Use the theme indicated by the `light` field. - `"dark"` - Use the theme indicated by the `dark` field. Thank you to @Yesterday17 for taking a first stab at this in #6881! Release Notes: - Added support for configuring both a light and dark theme and switching between them based on system preference.
This commit is contained in:
parent
b59f925933
commit
a80a3b8706
7 changed files with 167 additions and 24 deletions
|
@ -43,7 +43,7 @@ use std::{
|
|||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use theme::{ActiveTheme, ThemeRegistry, ThemeSettings};
|
||||
use theme::{ActiveTheme, SystemAppearance, ThemeRegistry, ThemeSettings};
|
||||
use util::{
|
||||
async_maybe,
|
||||
http::{self, HttpClient, ZedHttpClient},
|
||||
|
@ -912,8 +912,10 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
|||
theme_registry.load_user_themes(themes_dir, fs).await?;
|
||||
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) {
|
||||
if let Some(theme_selection) = theme_settings.theme_selection.clone() {
|
||||
let theme_name = theme_selection.theme(*SystemAppearance::global(cx));
|
||||
|
||||
if let Some(_theme) = theme_settings.switch_theme(&theme_name, cx) {
|
||||
ThemeSettings::override_global(theme_settings, cx);
|
||||
}
|
||||
}
|
||||
|
@ -949,11 +951,14 @@ fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
|||
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_selection) =
|
||||
theme_settings.theme_selection.clone()
|
||||
{
|
||||
let theme_name =
|
||||
theme_selection.theme(*SystemAppearance::global(cx));
|
||||
|
||||
if let Some(_theme) =
|
||||
theme_settings.switch_theme(&requested_theme, cx)
|
||||
theme_settings.switch_theme(&theme_name, cx)
|
||||
{
|
||||
ThemeSettings::override_global(theme_settings, cx);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue