From de7647108e831b9201483b665c99d6527964d2ce Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 7 Apr 2025 23:42:37 +0200 Subject: fix: custom theme Default changing between calls, missing `apply_options`s --- material_theme/src/lib.rs | 15 ++++++++++----- src/theme.rs | 6 ++++-- 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 = 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 { slice .iter() @@ -97,8 +100,7 @@ impl From 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") } } -- cgit v1.2.3