From bd718a9623a9101d922560bbe6878efa71610341 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Fri, 10 May 2024 07:50:33 +0100 Subject: [PATCH] core: save app themes as map with any text key --- src/Simplex/Chat/AppSettings.hs | 3 ++- src/Simplex/Chat/Types/UITheme.hs | 37 ++----------------------------- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/Simplex/Chat/AppSettings.hs b/src/Simplex/Chat/AppSettings.hs index 6996cc1d87..851dfc4767 100644 --- a/src/Simplex/Chat/AppSettings.hs +++ b/src/Simplex/Chat/AppSettings.hs @@ -9,6 +9,7 @@ import Control.Applicative ((<|>)) import Data.Aeson (FromJSON (..), (.:?)) import qualified Data.Aeson as J import qualified Data.Aeson.TH as JQ +import Data.Map.Strict (Map) import Data.Maybe (fromMaybe) import Data.Text (Text) import Simplex.Chat.Types.UITheme @@ -48,7 +49,7 @@ data AppSettings = AppSettings uiProfileImageCornerRadius :: Maybe Double, uiColorScheme :: Maybe UIColorScheme, uiDarkColorScheme :: Maybe DarkColorScheme, - uiThemes :: Maybe UIThemes + uiThemes :: Maybe (Map Text UITheme) } deriving (Show) diff --git a/src/Simplex/Chat/Types/UITheme.hs b/src/Simplex/Chat/Types/UITheme.hs index 9f9c106d1f..cd07012f45 100644 --- a/src/Simplex/Chat/Types/UITheme.hs +++ b/src/Simplex/Chat/Types/UITheme.hs @@ -8,25 +8,16 @@ module Simplex.Chat.Types.UITheme where import Data.Aeson (FromJSON (..), ToJSON (..)) import qualified Data.Aeson as J import qualified Data.Aeson.TH as JQ -import qualified Data.Attoparsec.ByteString.Char8 as A import Data.Char (toLower) import Data.Maybe (fromMaybe) +import Data.Text (Text) import Database.SQLite.Simple.FromField (FromField (..)) import Database.SQLite.Simple.ToField (ToField (..)) import Simplex.Chat.Types.Util -import Simplex.Messaging.Encoding.String import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, enumJSON, fromTextField_) -import Simplex.Messaging.Util ((<$?>)) - -data UIThemes = UIThemes - { light :: Maybe UITheme, - dark :: Maybe UITheme, - simplex :: Maybe UITheme - } - deriving (Eq, Show) data UITheme = UITheme - { base :: ThemeColorScheme, + { base :: Text, wallpaper :: Maybe ChatWallpaper, colors :: UIColors } @@ -48,9 +39,6 @@ data UIThemeEntityOverride = UIThemeEntityOverride } deriving (Eq, Show) -data ThemeColorScheme = TCSLight | TCSDark | TCSSimplex - deriving (Eq, Show) - data UIColorScheme = UCSSystem | UCSLight @@ -61,25 +49,6 @@ data UIColorScheme data DarkColorScheme = DCSDark | DCSSimplex deriving (Show) -instance StrEncoding ThemeColorScheme where - strEncode = \case - TCSLight -> "LIGHT" - TCSDark -> "DARK" - TCSSimplex -> "SIMPLEX" - strDecode = \case - "LIGHT" -> Right TCSLight - "DARK" -> Right TCSDark - "SIMPLEX" -> Right TCSSimplex - _ -> Left "bad ColorScheme" - strP = strDecode <$?> A.takeTill (== ' ') - -instance FromJSON ThemeColorScheme where - parseJSON = strParseJSON "ThemeColorScheme" - -instance ToJSON ThemeColorScheme where - toJSON = strToJSON - toEncoding = strToJEncoding - data ChatWallpaper = ChatWallpaper { preset :: Maybe ChatWallpaperPreset, imageFile :: Maybe FilePath, @@ -157,8 +126,6 @@ $(JQ.deriveJSON defaultJSON ''UIThemeEntityOverrides) $(JQ.deriveJSON defaultJSON ''UITheme) -$(JQ.deriveJSON defaultJSON ''UIThemes) - instance ToField UIThemeEntityOverrides where toField = toField . encodeJSON