Skip to content

Commit

Permalink
fix: more UX friendly cycle between themes
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Jun 8, 2024
1 parent ebb0a25 commit 68a41eb
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,33 @@ pub enum ThemeVariant {

impl ThemeVariant {
pub fn next(self) -> Self {
match self {
Self::System => Self::Dark,
Self::Dark => Self::Light,
Self::Light => Self::System,
let system_theme = use_preferred_theme();
let is_dark = matches!(*system_theme.read(), PreferredTheme::Dark);

if is_dark {
match self {
Self::System => Self::Light,
Self::Light => Self::Dark,
Self::Dark => Self::System,
}
} else {
match self {
Self::System => Self::Dark,
Self::Dark => Self::Light,
Self::Light => Self::System,
}
}
}

pub fn next_icon(self) -> &'static str {
self.next().icon()
}

pub fn icon(&self) -> &'static str {
match self {
ThemeVariant::System => icons::MOON,
ThemeVariant::Dark => icons::SUN,
ThemeVariant::Light => icons::CONTRAST,
ThemeVariant::System => icons::CONTRAST,
ThemeVariant::Dark => icons::MOON,
ThemeVariant::Light => icons::SUN,
}
}

Expand Down

0 comments on commit 68a41eb

Please sign in to comment.