fix(appearance): reload system theme after building themes
This commit is contained in:
parent
20fc48a8d7
commit
505d6e5711
1 changed files with 47 additions and 38 deletions
|
|
@ -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<Task<app::Message>> = 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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue