Reload theme using ThemeSettings::reload_current_theme
(#7522)
This PR updates the various spots where we reload the theme to use `ThemeSettings::reload_current_theme` instead of duplicating the code each time. Release Notes: - N/A
This commit is contained in:
parent
45cf36e870
commit
374c8a4c8c
3 changed files with 8 additions and 36 deletions
|
@ -34,6 +34,10 @@ pub struct ThemeSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThemeSettings {
|
impl ThemeSettings {
|
||||||
|
/// Reloads the current theme.
|
||||||
|
///
|
||||||
|
/// Reads the [`ThemeSettings`] to know which theme should be loaded,
|
||||||
|
/// taking into account the current [`SystemAppearance`].
|
||||||
pub fn reload_current_theme(cx: &mut AppContext) {
|
pub fn reload_current_theme(cx: &mut AppContext) {
|
||||||
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
||||||
|
|
||||||
|
|
|
@ -687,15 +687,7 @@ impl Workspace {
|
||||||
|
|
||||||
*SystemAppearance::global_mut(cx) = SystemAppearance(window_appearance.into());
|
*SystemAppearance::global_mut(cx) = SystemAppearance(window_appearance.into());
|
||||||
|
|
||||||
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
ThemeSettings::reload_current_theme(cx);
|
||||||
|
|
||||||
if let Some(theme_selection) = theme_settings.theme_selection.clone() {
|
|
||||||
let theme_name = theme_selection.theme(window_appearance.into());
|
|
||||||
|
|
||||||
if let Some(_theme) = theme_settings.switch_theme(&theme_name, cx) {
|
|
||||||
ThemeSettings::override_global(theme_settings, cx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
cx.observe(&left_dock, |this, _, cx| {
|
cx.observe(&left_dock, |this, _, cx| {
|
||||||
this.serialize_workspace(cx);
|
this.serialize_workspace(cx);
|
||||||
|
|
|
@ -918,16 +918,7 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
theme_registry.load_user_themes(themes_dir, fs).await?;
|
theme_registry.load_user_themes(themes_dir, fs).await?;
|
||||||
cx.update(|cx| {
|
cx.update(|cx| ThemeSettings::reload_current_theme(cx))?;
|
||||||
let mut theme_settings = ThemeSettings::get_global(cx).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(&theme_name, cx) {
|
|
||||||
ThemeSettings::override_global(theme_settings, cx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
}
|
}
|
||||||
|
@ -958,23 +949,8 @@ fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
|
||||||
.await
|
.await
|
||||||
.log_err()
|
.log_err()
|
||||||
{
|
{
|
||||||
cx.update(|cx| {
|
cx.update(|cx| ThemeSettings::reload_current_theme(cx))
|
||||||
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
.log_err();
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.log_err();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue