summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--material_theme/src/lib.rs15
-rw-r--r--src/theme.rs6
2 files changed, 14 insertions, 7 deletions
diff --git a/material_theme/src/lib.rs b/material_theme/src/lib.rs
index 38a94b0..930e511 100644
--- a/material_theme/src/lib.rs
+++ b/material_theme/src/lib.rs
@@ -69,12 +69,17 @@ impl Clone for Theme {
impl Default for Theme {
fn default() -> Self {
- match dark_light::detect().unwrap_or(dark_light::Mode::Unspecified) {
- dark_light::Mode::Dark | dark_light::Mode::Unspecified => {
- DARK.clone()
+ static DEFAULT: LazyLock<Theme> = LazyLock::new(|| {
+ match dark_light::detect().unwrap_or(dark_light::Mode::Unspecified)
+ {
+ dark_light::Mode::Dark | dark_light::Mode::Unspecified => {
+ DARK.clone()
+ }
+ dark_light::Mode::Light => LIGHT.clone(),
}
- dark_light::Mode::Light => LIGHT.clone(),
- }
+ });
+
+ DEFAULT.clone()
}
}
diff --git a/src/theme.rs b/src/theme.rs
index 232f309..b721ddc 100644
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -6,6 +6,9 @@ use serde::Deserialize;
use crate::config::Config;
+const DEFAULT_THEME_CONTENT: &str =
+ include_str!("../assets/themes/rose_pine.toml");
+
pub fn theme_index(theme_name: &str, slice: &[iced::Theme]) -> Option<usize> {
slice
.iter()
@@ -97,8 +100,7 @@ impl From<Theme> for iced::Theme {
impl Default for Theme {
fn default() -> Self {
- toml::from_str(include_str!("../assets/themes/rose_pine.toml"))
- .expect("parse default theme")
+ toml::from_str(DEFAULT_THEME_CONTENT).expect("parse default theme")
}
}