From c5a23faf7c01cb39797a5e5d28fdec7d92ffa4b1 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Fri, 16 Feb 2024 11:28:34 -0500 Subject: [PATCH] Fall back to One themes if the selected theme doesn't exist (#7911) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR makes it so the One themes—One Dark and One Light—are used as a fallback when trying to reload a theme that no longer exists in the registry. This makes it so when an extension providing the current theme is removed, the active theme will change to either One Dark or One Light (based on the system appearance) instead of retaining a cached version of the theme. Release Notes: - Changed the behavior when uninstalling a theme to default to One Dark or One Light (based on system appearance) rather than keeping a cached version of the old theme. --- crates/theme/src/settings.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/theme/src/settings.rs b/crates/theme/src/settings.rs index 51e48180aee05c7503454ad79b47b5fb26a4e21d..48f745513ef751ce020371f4ac4aeef88a0a3536 100644 --- a/crates/theme/src/settings.rs +++ b/crates/theme/src/settings.rs @@ -40,9 +40,20 @@ impl ThemeSettings { /// taking into account the current [`SystemAppearance`]. pub fn reload_current_theme(cx: &mut AppContext) { let mut theme_settings = ThemeSettings::get_global(cx).clone(); + let system_appearance = SystemAppearance::global(cx); if let Some(theme_selection) = theme_settings.theme_selection.clone() { - let theme_name = theme_selection.theme(*SystemAppearance::global(cx)); + let mut theme_name = theme_selection.theme(*system_appearance); + + // If the selected theme doesn't exist, fall back to a default theme + // based on the system appearance. + let theme_registry = ThemeRegistry::global(cx); + if theme_registry.get(&theme_name).ok().is_none() { + theme_name = match *system_appearance { + Appearance::Light => "One Light", + Appearance::Dark => "One Dark", + }; + }; if let Some(_theme) = theme_settings.switch_theme(&theme_name, cx) { ThemeSettings::override_global(theme_settings, cx);