From 72bf6fa08b6909ac837d155dff6bee4cf283d821 Mon Sep 17 00:00:00 2001 From: Rudxain Date: Thu, 4 Jul 2024 07:05:31 -0400 Subject: [PATCH 1/8] feat(theme): Add `Auto` `enum` variant --- src/core/theme.rs | 128 +++++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 54 deletions(-) diff --git a/src/core/theme.rs b/src/core/theme.rs index 6d30d84..3fee5b1 100644 --- a/src/core/theme.rs +++ b/src/core/theme.rs @@ -1,11 +1,18 @@ +use dark_light; use iced::{color, Color}; #[derive(Default, Debug, PartialEq, Eq, Copy, Clone)] +/// Color scheme pub enum Theme { #[default] + /// `Dark`-ish and purple Lupin, + /// white on black Dark, + /// black on white Light, + /// `Dark` or `Light`, according to `dark_light` + Auto, } #[derive(Debug, Clone, Copy)] @@ -39,62 +46,73 @@ pub struct ColorPalette { } impl Theme { - pub const ALL: [Self; 3] = [Self::Lupin, Self::Dark, Self::Light]; + pub const ALL: [Self; 4] = [Self::Lupin, Self::Dark, Self::Light, Self::Auto]; + pub fn palette(self) -> ColorPalette { + const DARK: ColorPalette = ColorPalette { + base: BaseColors { + background: color!(0x111111), + foreground: color!(0x1C1C1C), + }, + normal: NormalColors { + primary: color!(0x5E4266), + secondary: color!(0x386e50), + surface: color!(0x828282), + error: color!(0x992B2B), + }, + bright: BrightColors { + primary: color!(0xBA84FC), + secondary: color!(0x49eb7a), + surface: color!(0xE0E0E0), + error: color!(0xC13047), + }, + }; + const LIGHT: ColorPalette = ColorPalette { + base: BaseColors { + background: color!(0xEEEEEE), + foreground: color!(0xE0E0E0), + }, + normal: NormalColors { + primary: color!(0x818181), + secondary: color!(0xF9D659), + surface: color!(0x818181), + error: color!(0x992B2B), + }, + bright: BrightColors { + primary: color!(0x673AB7), + secondary: color!(0x3797A4), + surface: color!(0x000000), + error: color!(0xC13047), + }, + }; + const LUPIN: ColorPalette = ColorPalette { + base: BaseColors { + background: color!(0x282a36), + foreground: color!(0x353746), + }, + normal: NormalColors { + primary: color!(0x58406F), + secondary: color!(0x386e50), + surface: color!(0xa2a4a3), + error: color!(0xA13034), + }, + bright: BrightColors { + primary: color!(0xbd94f9), + secondary: color!(0x49eb7a), + surface: color!(0xf4f8f3), + error: color!(0xE63E6D), + }, + }; match self { - Self::Dark => ColorPalette { - base: BaseColors { - background: color!(0x111111), - foreground: color!(0x1C1C1C), - }, - normal: NormalColors { - primary: color!(0x5E4266), - secondary: color!(0x386e50), - surface: color!(0x828282), - error: color!(0x992B2B), - }, - bright: BrightColors { - primary: color!(0xBA84FC), - secondary: color!(0x49eb7a), - surface: color!(0xE0E0E0), - error: color!(0xC13047), - }, - }, - Self::Light => ColorPalette { - base: BaseColors { - background: color!(0xEEEEEE), - foreground: color!(0xE0E0E0), - }, - normal: NormalColors { - primary: color!(0x818181), - secondary: color!(0xF9D659), - surface: color!(0x818181), - error: color!(0x992B2B), - }, - bright: BrightColors { - primary: color!(0x673AB7), - secondary: color!(0x3797A4), - surface: color!(0x000000), - error: color!(0xC13047), - }, - }, - Self::Lupin => ColorPalette { - base: BaseColors { - background: color!(0x282a36), - foreground: color!(0x353746), - }, - normal: NormalColors { - primary: color!(0x58406F), - secondary: color!(0x386e50), - surface: color!(0xa2a4a3), - error: color!(0xA13034), - }, - bright: BrightColors { - primary: color!(0xbd94f9), - secondary: color!(0x49eb7a), - surface: color!(0xf4f8f3), - error: color!(0xE63E6D), - }, + Self::Dark => DARK, + Self::Light => LIGHT, + Self::Lupin => LUPIN, + Self::Auto => match dark_light::detect() { + dark_light::Mode::Dark => DARK, + dark_light::Mode::Light => LIGHT, + // we should use `default` somehow, + // rather than hard-coding Lupin + _ => LUPIN, }, } } @@ -109,6 +127,8 @@ impl std::fmt::Display for Theme { Self::Dark => "Dark", Self::Light => "Light", Self::Lupin => "Lupin", + // should it be "Follow System"? + Self::Auto => "Auto (sync on startup)", } ) } From 5f43725ac4048a192132bbe6a0e3207edca2b0a0 Mon Sep 17 00:00:00 2001 From: Rudxain Date: Thu, 4 Jul 2024 08:22:15 -0400 Subject: [PATCH 2/8] fix(config): Use actual `Theme::default` rather than "Dark" --- src/core/config.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/config.rs b/src/core/config.rs index 3d9f1b0..b23b765 100644 --- a/src/core/config.rs +++ b/src/core/config.rs @@ -1,5 +1,8 @@ -use crate::core::sync::{get_android_sdk, User}; use crate::core::utils::DisplayablePath; +use crate::core::{ + sync::{get_android_sdk, User}, + theme::Theme, +}; use crate::gui::views::settings::Settings; use crate::CACHE_DIR; use crate::CONFIG_DIR; @@ -43,7 +46,7 @@ pub struct DeviceSettings { impl Default for GeneralSettings { fn default() -> Self { Self { - theme: String::from("Dark"), + theme: Theme::default().to_string(), expert_mode: false, backup_folder: CACHE_DIR.join("backups"), } From 76aba1e54829dd5fef2f91294f837dbcfa28e3e4 Mon Sep 17 00:00:00 2001 From: Frigyes Erdosi Szucs Date: Mon, 8 Jul 2024 13:13:51 +0200 Subject: [PATCH 3/8] Auto by default --- src/core/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/utils.rs b/src/core/utils.rs index 2f59e2d..83a086a 100644 --- a/src/core/utils.rs +++ b/src/core/utils.rs @@ -63,7 +63,7 @@ pub fn string_to_theme(theme: &str) -> Theme { "Dark" => Theme::Dark, "Light" => Theme::Light, "Lupin" => Theme::Lupin, - _ => Theme::Dark, + _ => Theme::Auto, } } From d2098d305033cfdf5cc368a0546633d76a2d2a30 Mon Sep 17 00:00:00 2001 From: Frigyes Erdosi Szucs Date: Mon, 8 Jul 2024 15:28:43 +0200 Subject: [PATCH 4/8] feat(theme): set theme to auto by default --- src/core/theme.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/theme.rs b/src/core/theme.rs index 3fee5b1..fe97c5e 100644 --- a/src/core/theme.rs +++ b/src/core/theme.rs @@ -5,14 +5,14 @@ use iced::{color, Color}; /// Color scheme pub enum Theme { #[default] + /// `Dark` or `Light`, according to `dark_light` + Auto, /// `Dark`-ish and purple Lupin, /// white on black Dark, /// black on white Light, - /// `Dark` or `Light`, according to `dark_light` - Auto, } #[derive(Debug, Clone, Copy)] @@ -127,8 +127,7 @@ impl std::fmt::Display for Theme { Self::Dark => "Dark", Self::Light => "Light", Self::Lupin => "Lupin", - // should it be "Follow System"? - Self::Auto => "Auto (sync on startup)", + Self::Auto => "Auto (follow system theme)", } ) } From ae4d56d6bab7a8e57af7f29b9f2c5761e2d7ae48 Mon Sep 17 00:00:00 2001 From: Rudxain Date: Mon, 8 Jul 2024 13:27:41 -0400 Subject: [PATCH 5/8] chore(theme): move `Auto` to 0th position --- src/core/theme.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/theme.rs b/src/core/theme.rs index fe97c5e..cce0b61 100644 --- a/src/core/theme.rs +++ b/src/core/theme.rs @@ -46,7 +46,7 @@ pub struct ColorPalette { } impl Theme { - pub const ALL: [Self; 4] = [Self::Lupin, Self::Dark, Self::Light, Self::Auto]; + pub const ALL: [Self; 4] = [Self::Auto, Self::Lupin, Self::Dark, Self::Light]; pub fn palette(self) -> ColorPalette { const DARK: ColorPalette = ColorPalette { From e40951eec5569f616a87277051961a00ae862ea9 Mon Sep 17 00:00:00 2001 From: Rudxain Date: Mon, 8 Jul 2024 13:43:48 -0400 Subject: [PATCH 6/8] refactor(theme): `string_to_theme` is more correct --- src/core/utils.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/utils.rs b/src/core/utils.rs index 83a086a..9b87847 100644 --- a/src/core/utils.rs +++ b/src/core/utils.rs @@ -63,7 +63,9 @@ pub fn string_to_theme(theme: &str) -> Theme { "Dark" => Theme::Dark, "Light" => Theme::Light, "Lupin" => Theme::Lupin, - _ => Theme::Auto, + // Auto uses `Display`, so it doesn't have a canonical repr + t if t.starts_with("Auto") => Theme::Auto, + _ => Theme::default(), } } From 0dda83a6f1de53a96f1c12c295032371ca25f217 Mon Sep 17 00:00:00 2001 From: Rudxain Date: Mon, 8 Jul 2024 13:49:46 -0400 Subject: [PATCH 7/8] docs(theme): update comment about default (#540) --- src/core/theme.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/theme.rs b/src/core/theme.rs index cce0b61..16bf88f 100644 --- a/src/core/theme.rs +++ b/src/core/theme.rs @@ -110,8 +110,7 @@ impl Theme { Self::Auto => match dark_light::detect() { dark_light::Mode::Dark => DARK, dark_light::Mode::Light => LIGHT, - // we should use `default` somehow, - // rather than hard-coding Lupin + // TO-DO: await #540 _ => LUPIN, }, } From ff150c372a7b7f18dad6da75b6e896ae3b0d3e92 Mon Sep 17 00:00:00 2001 From: Frigyes Erdosi Szucs Date: Tue, 9 Jul 2024 10:31:34 +0200 Subject: [PATCH 8/8] refactor(theme): dark_light has exhaustive list of states --- src/core/theme.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/theme.rs b/src/core/theme.rs index 16bf88f..35f0943 100644 --- a/src/core/theme.rs +++ b/src/core/theme.rs @@ -110,8 +110,8 @@ impl Theme { Self::Auto => match dark_light::detect() { dark_light::Mode::Dark => DARK, dark_light::Mode::Light => LIGHT, - // TO-DO: await #540 - _ => LUPIN, + // If the mode can't be detected, fall back to dark. + dark_light::Mode::Default => DARK, }, } }