Skip to content

Commit

Permalink
core: save app themes as map with any text key
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed May 10, 2024
1 parent 76248b4 commit bd718a9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/Simplex/Chat/AppSettings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
37 changes: 2 additions & 35 deletions src/Simplex/Chat/Types/UITheme.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -48,9 +39,6 @@ data UIThemeEntityOverride = UIThemeEntityOverride
}
deriving (Eq, Show)

data ThemeColorScheme = TCSLight | TCSDark | TCSSimplex
deriving (Eq, Show)

data UIColorScheme
= UCSSystem
| UCSLight
Expand All @@ -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,
Expand Down Expand Up @@ -157,8 +126,6 @@ $(JQ.deriveJSON defaultJSON ''UIThemeEntityOverrides)

$(JQ.deriveJSON defaultJSON ''UITheme)

$(JQ.deriveJSON defaultJSON ''UIThemes)

instance ToField UIThemeEntityOverrides where
toField = toField . encodeJSON

Expand Down

0 comments on commit bd718a9

Please sign in to comment.