Skip to content

Commit

Permalink
cleanup (applet): settings already has the system theme by default
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Aug 14, 2023
1 parent e7269a2 commit c2be970
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/app/applet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl CosmicAppletHelper {
let (width, height) = self.suggested_size();
let width = u32::from(width);
let height = u32::from(height);
super::Settings::default()
let settings = super::Settings::default()
.size((width + APPLET_PADDING * 2, height + APPLET_PADDING * 2))
.size_limits(
Limits::NONE
Expand All @@ -116,8 +116,11 @@ impl CosmicAppletHelper {
.resizable(None)
.default_text_size(18.0)
.default_font(crate::font::FONT)
.transparent(true)
.theme(self.theme())
.transparent(true);
if let Some(theme) = self.theme() {
settings.theme(theme);
}
settings
}

#[must_use]
Expand Down Expand Up @@ -199,26 +202,11 @@ impl CosmicAppletHelper {
}

#[must_use]
pub fn theme(&self) -> theme::Theme {
pub fn theme(&self) -> Option<theme::Theme> {
match self.background {
CosmicPanelBackground::ThemeDefault | CosmicPanelBackground::Color(_) => {
let Ok(helper) = cosmic_config::Config::new(
cosmic_theme::NAME,
cosmic_theme::Theme::<CssColor>::version(),
) else {
return theme::Theme::dark();
};
let t =
cosmic_theme::Theme::get_entry(&helper).unwrap_or_else(|(errors, theme)| {
for err in errors {
error!("{:?}", err);
}
theme
});
theme::Theme::custom(Arc::new(t))
}
CosmicPanelBackground::Dark => theme::Theme::dark(),
CosmicPanelBackground::Light => theme::Theme::light(),
_ => None,
}
}
}
Expand Down

0 comments on commit c2be970

Please sign in to comment.