Remove cx from ThemeSettings (#38836)
Before this change the active theme and icon theme were retrofitted onto the ThemeSettings. Now they're in their own new global (GlobalTheme::theme(cx) and GlobalTheme::icon_theme(cx)) This lets us remove cx from the settings traits, and tidy up a few other things along the way. Release Notes: - N/A
This commit is contained in:
+43
-44
@@ -41,8 +41,8 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
use theme::{
|
||||
ActiveTheme, IconThemeNotFoundError, SystemAppearance, ThemeNotFoundError, ThemeRegistry,
|
||||
ThemeSettings,
|
||||
ActiveTheme, GlobalTheme, IconThemeNotFoundError, SystemAppearance, ThemeNotFoundError,
|
||||
ThemeRegistry, ThemeSettings,
|
||||
};
|
||||
use util::{ResultExt, TryFutureExt, maybe};
|
||||
use uuid::Uuid;
|
||||
@@ -542,7 +542,6 @@ pub fn main() {
|
||||
cx,
|
||||
);
|
||||
|
||||
SystemAppearance::init(cx);
|
||||
theme::init(theme::LoadThemes::All(Box::new(Assets)), cx);
|
||||
theme_extension::init(
|
||||
extension_host_proxy.clone(),
|
||||
@@ -1363,49 +1362,49 @@ fn eager_load_active_theme_and_icon_theme(fs: Arc<dyn Fs>, cx: &App) {
|
||||
let theme_settings = ThemeSettings::get_global(cx);
|
||||
let appearance = SystemAppearance::global(cx).0;
|
||||
|
||||
if let Some(theme_selection) = theme_settings.theme_selection.as_ref() {
|
||||
let theme_name = theme_selection.theme(appearance);
|
||||
if matches!(theme_registry.get(theme_name), Err(ThemeNotFoundError(_)))
|
||||
&& let Some(theme_path) = extension_store.read(cx).path_to_extension_theme(theme_name)
|
||||
{
|
||||
cx.spawn({
|
||||
let theme_registry = theme_registry.clone();
|
||||
let fs = fs.clone();
|
||||
async move |cx| {
|
||||
theme_registry.load_user_theme(&theme_path, fs).await?;
|
||||
let theme_name = theme_settings.theme.name(appearance);
|
||||
if matches!(
|
||||
theme_registry.get(&theme_name.0),
|
||||
Err(ThemeNotFoundError(_))
|
||||
) && let Some(theme_path) = extension_store
|
||||
.read(cx)
|
||||
.path_to_extension_theme(&theme_name.0)
|
||||
{
|
||||
cx.spawn({
|
||||
let theme_registry = theme_registry.clone();
|
||||
let fs = fs.clone();
|
||||
async move |cx| {
|
||||
theme_registry.load_user_theme(&theme_path, fs).await?;
|
||||
|
||||
cx.update(|cx| {
|
||||
ThemeSettings::reload_current_theme(cx);
|
||||
})
|
||||
}
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
cx.update(|cx| {
|
||||
GlobalTheme::reload_theme(cx);
|
||||
})
|
||||
}
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
if let Some(icon_theme_selection) = theme_settings.icon_theme_selection.as_ref() {
|
||||
let icon_theme_name = icon_theme_selection.icon_theme(appearance);
|
||||
if matches!(
|
||||
theme_registry.get_icon_theme(icon_theme_name),
|
||||
Err(IconThemeNotFoundError(_))
|
||||
) && let Some((icon_theme_path, icons_root_path)) = extension_store
|
||||
.read(cx)
|
||||
.path_to_extension_icon_theme(icon_theme_name)
|
||||
{
|
||||
cx.spawn({
|
||||
let fs = fs.clone();
|
||||
async move |cx| {
|
||||
theme_registry
|
||||
.load_icon_theme(&icon_theme_path, &icons_root_path, fs)
|
||||
.await?;
|
||||
let icon_theme_name = theme_settings.icon_theme.name(appearance);
|
||||
if matches!(
|
||||
theme_registry.get_icon_theme(&icon_theme_name.0),
|
||||
Err(IconThemeNotFoundError(_))
|
||||
) && let Some((icon_theme_path, icons_root_path)) = extension_store
|
||||
.read(cx)
|
||||
.path_to_extension_icon_theme(&icon_theme_name.0)
|
||||
{
|
||||
cx.spawn({
|
||||
let fs = fs.clone();
|
||||
async move |cx| {
|
||||
theme_registry
|
||||
.load_icon_theme(&icon_theme_path, &icons_root_path, fs)
|
||||
.await?;
|
||||
|
||||
cx.update(|cx| {
|
||||
ThemeSettings::reload_current_icon_theme(cx);
|
||||
})
|
||||
}
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
cx.update(|cx| {
|
||||
GlobalTheme::reload_icon_theme(cx);
|
||||
})
|
||||
}
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1433,7 +1432,7 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut App) {
|
||||
}
|
||||
}
|
||||
theme_registry.load_user_themes(themes_dir, fs).await?;
|
||||
cx.update(ThemeSettings::reload_current_theme)?;
|
||||
cx.update(GlobalTheme::reload_theme)?;
|
||||
}
|
||||
anyhow::Ok(())
|
||||
}
|
||||
@@ -1459,7 +1458,7 @@ fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut App) {
|
||||
.await
|
||||
.log_err()
|
||||
{
|
||||
cx.update(ThemeSettings::reload_current_theme).log_err();
|
||||
cx.update(GlobalTheme::reload_theme).log_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1994,8 +1994,11 @@ mod tests {
|
||||
path::{Path, PathBuf},
|
||||
time::Duration,
|
||||
};
|
||||
use theme::{ThemeRegistry, ThemeSettings};
|
||||
use util::{path, rel_path::rel_path};
|
||||
use theme::ThemeRegistry;
|
||||
use util::{
|
||||
path,
|
||||
rel_path::{RelPath, rel_path},
|
||||
};
|
||||
use workspace::{
|
||||
NewFile, OpenOptions, OpenVisible, SERIALIZATION_THROTTLE_TIME, SaveIntent, SplitDirection,
|
||||
WorkspaceHandle,
|
||||
@@ -4593,7 +4596,7 @@ mod tests {
|
||||
for theme_name in themes.list().into_iter().map(|meta| meta.name) {
|
||||
let theme = themes.get(&theme_name).unwrap();
|
||||
assert_eq!(theme.name, theme_name);
|
||||
if theme.name == ThemeSettings::get(None, cx).active_theme.name {
|
||||
if theme.name.as_ref() == "One Dark" {
|
||||
has_default_theme = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user