From 505d6e5711b26c46f07a28948dc0af60058f1a36 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Tue, 12 Aug 2025 20:19:32 +0200 Subject: [PATCH] fix(appearance): reload system theme after building themes --- .../pages/desktop/appearance/theme_manager.rs | 85 ++++++++++--------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/cosmic-settings/src/pages/desktop/appearance/theme_manager.rs b/cosmic-settings/src/pages/desktop/appearance/theme_manager.rs index 2ddb5b9..10ba16a 100644 --- a/cosmic-settings/src/pages/desktop/appearance/theme_manager.rs +++ b/cosmic-settings/src/pages/desktop/appearance/theme_manager.rs @@ -8,7 +8,6 @@ use cosmic::iced_core::Color; use cosmic::Task; use cosmic::theme::ThemeType; -use std::borrow::BorrowMut; use std::sync::Arc; use crate::app; @@ -175,49 +174,59 @@ impl Manager { } } - let mut tasks: Vec> = Vec::new(); - let customizers = match stage { - ThemeStaged::Current => vec![self.selected_customizer_mut()], - ThemeStaged::Both => vec![self.light.borrow_mut(), self.dark.borrow_mut()], - }; - - customizers.into_iter().for_each(|customizer| { + let map_data_fn = |customizer: &ThemeCustomizer| { let builder = customizer.builder.0.clone(); let (current_theme, config) = customizer.theme.clone(); + (builder, current_theme, config) + }; - tasks.push( - cosmic::Task::future(async move { - if let Some(config) = config { - let new_theme = builder.build(); - theme_transaction!(config, current_theme, new_theme, { - accent; - accent_text; - accent_button; - background; - button; - destructive; - destructive_button; - link_button; - icon_button; - palette; - primary; - secondary; - shade; - success; - text_button; - warning; - warning_button; - window_hint; - }); - } - }) - .discard(), - ); + let current = map_data_fn(if self.mode.0.is_dark { + &self.dark + } else { + &self.light }); - cosmic::task::batch(tasks).chain(cosmic::task::future(async { + let other = if let ThemeStaged::Both = stage { + Some(map_data_fn(if !self.mode.0.is_dark { + &self.dark + } else { + &self.light + })) + } else { + None + }; + + let mut data = std::iter::once(current).chain(other.into_iter()); + + cosmic::task::future(async move { + while let Some((builder, current_theme, config)) = data.next() { + if let Some(config) = config { + let new_theme = builder.build(); + theme_transaction!(config, current_theme, new_theme, { + accent; + accent_text; + accent_button; + background; + button; + destructive; + destructive_button; + link_button; + icon_button; + palette; + primary; + secondary; + shade; + success; + text_button; + warning; + warning_button; + window_hint; + }); + } + } + app::Message::SetTheme(cosmic::theme::system_preference()) - })) + }) } #[inline]