Repository: lapce/lapce (language: rust)

Issue:
Lapce goes crazy when uninstall theme without changing to another.
## Lapce Version
0.4.0

## System information

# System Details Report
---

## Report details
- **Date generated:**                              2024-04-25 09:58:49

## Hardware Information:
- **Hardware Model:**                              Dell Inc. OptiPlex 3080
- **Memory:**                                      8.0 GiB
- **Processor:**                                   Intel® Core™ i5-10500 × 12
- **Graphics:**                                    Intel® UHD Graphics 630 (CML GT2)
- **Disk Capacity:**                               1.3 TB

## Software Information:
- **Firmware Version:**                            2.24.0
- **OS Name:**                                     Fedora Linux 39 (Workstation Edition)
- **OS Build:**                                    (null)
- **OS Type:**                                     64-bit
- **GNOME Version:**                               45.5
- **Windowing System:**                            Wayland
- **Kernel Version:**                              Linux 6.8.7-200.fc39.x86_64


## Describe the bug
I installed a theme & select it from setting. but when i uninstalled it without changing the theme to default theme it goes crazy.
see below screenshot.

## Additional information



- screenshots
![Screenshot from 2024-04-25 09-57-28](https://github.com/lapce/lapce/assets/32354365/e467f8f7-38db-4d7c-a275-f9b0058055a4)

- logs
- theories about what might be going wrong
- workarounds that you used



Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c07f27d74a..b68cef3d91 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
 ### Features/Changes
 
 ### Bug Fixes
+- [#3203](https://github.com/lapce/lapce/pull/3203): Fallback to default theme is theme key is not found
 
 ## 0.4.0
 
diff --git a/lapce-app/src/config.rs b/lapce-app/src/config.rs
index a695027799..8e5a6ff9b7 100644
--- a/lapce-app/src/config.rs
+++ b/lapce-app/src/config.rs
@@ -68,10 +68,18 @@ static DEFAULT_DARK_THEME_COLOR_CONFIG: Lazy<ColorThemeConfig> = Lazy::new(|| {
     theme.get::<ColorThemeConfig>("color-theme")
     .expect("Failed to load default dark theme. This is likely due to a missing or misnamed field in dark-theme.toml")
 });
-static DEFAULT_ICON_THEME_CONFIG: Lazy<IconThemeConfig> = Lazy::new(|| {
-    let (_, theme) =
-        LapceConfig::load_icon_theme_from_str(DEFAULT_ICON_THEME).unwrap();
-    theme.get::<IconThemeConfig>("icon-theme")
+
+static DEFAULT_ICON_THEME_CONFIG: Lazy<config::Config> = Lazy::new(|| {
+    config::Config::builder()
+        .add_source(config::File::from_str(
+            DEFAULT_ICON_THEME,
+            config::FileFormat::Toml,
+        ))
+        .build()
+        .unwrap()
+});
+static DEFAULT_ICON_THEME_ICON_CONFIG: Lazy<IconThemeConfig> = Lazy::new(|| {
+    DEFAULT_ICON_THEME_CONFIG.get::<IconThemeConfig>("icon-theme")
     .expect("Failed to load default icon theme. This is likely due to a missing or misnamed field in icon-theme.toml")
 });
 
@@ -245,7 +253,7 @@ impl LapceConfig {
         let mut default_lapce_config: LapceConfig =
             DEFAULT_CONFIG.clone().try_deserialize().expect("Failed to deserialize default config, this likely indicates a missing or misnamed field in settings.toml");
         default_lapce_config.color_theme = DEFAULT_DARK_THEME_COLOR_CONFIG.clone();
-        default_lapce_config.icon_theme = DEFAULT_ICON_THEME_CONFIG.clone();
+        default_lapce_config.icon_theme = DEFAULT_ICON_THEME_ICON_CONFIG.clone();
         default_lapce_config.resolve_colors(None);
         default_lapce_config
     }
@@ -256,40 +264,39 @@ impl LapceConfig {
         let color_theme_config = self
             .available_color_themes
             .get(&self.core.color_theme.to_lowercase())
-            .map(|(_, config)| config);
+            .map(|(_, config)| config)
+            .unwrap_or(&DEFAULT_DARK_THEME_CONFIG);
 
         let icon_theme_config = self
             .available_icon_themes
             .get(&self.core.icon_theme.to_lowercase())
-            .map(|(_, config, _)| config);
+            .map(|(_, config, _)| config)
+            .unwrap_or(&DEFAULT_ICON_THEME_CONFIG);
 
         let icon_theme_path = self
             .available_icon_themes
             .get(&self.core.icon_theme.to_lowercase())
             .map(|(_, _, path)| path);
 
-        if color_theme_config.is_some() || icon_theme_config.is_some() {
-            if let Ok(new) = Self::merge_config(
-                workspace,
-                color_theme_config.cloned(),
-                icon_theme_config.cloned(),
-            )
-            .try_deserialize::<LapceConfig>()
-            {
-                self.core = new.core;
-                self.ui = new.ui;
-                self.editor = new.editor;
-                self.terminal = new.terminal;
-                self.terminal.get_indexed_colors();
-
-                self.color_theme = new.color_theme;
-                self.icon_theme = new.icon_theme;
-                if let Some(icon_theme_path) = icon_theme_path {
-                    self.icon_theme.path =
-                        icon_theme_path.clone().unwrap_or_default();
-                }
-                self.plugins = new.plugins;
-            }
+        if let Ok(new) = Self::merge_config(
+            workspace,
+            Some(color_theme_config.clone()),
+            Some(icon_theme_config.clone()),
+        )
+        .try_deserialize::<LapceConfig>()
+        {
+            self.core = new.core;
+            self.ui = new.ui;
+            self.editor = new.editor;
+            self.terminal = new.terminal;
+            self.terminal.get_indexed_colors();
+
+            self.color_theme = new.color_theme;
+            self.icon_theme = new.icon_theme;
+            if let Some(icon_theme_path) = icon_theme_path {
+                self.icon_theme.path = icon_theme_path.clone().unwrap_or_default();
+            }
+            self.plugins = new.plugins;
         }
         self.resolve_colors(Some(&default_lapce_config));
         self.update_id();
@@ -588,7 +595,7 @@ impl LapceConfig {
         });
 
         svg.unwrap_or_else(|| {
-            let name = DEFAULT_ICON_THEME_CONFIG.ui.get(icon).unwrap();
+            let name = DEFAULT_ICON_THEME_ICON_CONFIG.ui.get(icon).unwrap();
             self.svg_store.write().get_default_svg(name)
         })
     }


Test patch: