{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}

module Simplex.Chat.AppSettings where

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
import Simplex.Messaging.Client (NetworkConfig, defaultNetworkConfig)
import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, enumJSON)
import Simplex.Messaging.Util (catchAll_)

data AppPlatform = APIOS | APAndroid | APDesktop deriving (Int -> AppPlatform -> ShowS
[AppPlatform] -> ShowS
AppPlatform -> String
(Int -> AppPlatform -> ShowS)
-> (AppPlatform -> String)
-> ([AppPlatform] -> ShowS)
-> Show AppPlatform
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AppPlatform -> ShowS
showsPrec :: Int -> AppPlatform -> ShowS
$cshow :: AppPlatform -> String
show :: AppPlatform -> String
$cshowList :: [AppPlatform] -> ShowS
showList :: [AppPlatform] -> ShowS
Show)

data NotificationMode = NMOff | NMPeriodic | NMInstant deriving (Int -> NotificationMode -> ShowS
[NotificationMode] -> ShowS
NotificationMode -> String
(Int -> NotificationMode -> ShowS)
-> (NotificationMode -> String)
-> ([NotificationMode] -> ShowS)
-> Show NotificationMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NotificationMode -> ShowS
showsPrec :: Int -> NotificationMode -> ShowS
$cshow :: NotificationMode -> String
show :: NotificationMode -> String
$cshowList :: [NotificationMode] -> ShowS
showList :: [NotificationMode] -> ShowS
Show)

data NotificationPreviewMode = NPMHidden | NPMContact | NPMMessage deriving (Int -> NotificationPreviewMode -> ShowS
[NotificationPreviewMode] -> ShowS
NotificationPreviewMode -> String
(Int -> NotificationPreviewMode -> ShowS)
-> (NotificationPreviewMode -> String)
-> ([NotificationPreviewMode] -> ShowS)
-> Show NotificationPreviewMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NotificationPreviewMode -> ShowS
showsPrec :: Int -> NotificationPreviewMode -> ShowS
$cshow :: NotificationPreviewMode -> String
show :: NotificationPreviewMode -> String
$cshowList :: [NotificationPreviewMode] -> ShowS
showList :: [NotificationPreviewMode] -> ShowS
Show)

data LockScreenCalls = LSCDisable | LSCShow | LSCAccept deriving (Int -> LockScreenCalls -> ShowS
[LockScreenCalls] -> ShowS
LockScreenCalls -> String
(Int -> LockScreenCalls -> ShowS)
-> (LockScreenCalls -> String)
-> ([LockScreenCalls] -> ShowS)
-> Show LockScreenCalls
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LockScreenCalls -> ShowS
showsPrec :: Int -> LockScreenCalls -> ShowS
$cshow :: LockScreenCalls -> String
show :: LockScreenCalls -> String
$cshowList :: [LockScreenCalls] -> ShowS
showList :: [LockScreenCalls] -> ShowS
Show)

data AppSettings = AppSettings
  { AppSettings -> Maybe AppPlatform
appPlatform :: Maybe AppPlatform,
    AppSettings -> Maybe NetworkConfig
networkConfig :: Maybe NetworkConfig,
    AppSettings -> Maybe NetworkProxy
networkProxy :: Maybe NetworkProxy,
    AppSettings -> Maybe Bool
privacyEncryptLocalFiles :: Maybe Bool,
    AppSettings -> Maybe Bool
privacyAskToApproveRelays :: Maybe Bool,
    AppSettings -> Maybe Bool
privacyAcceptImages :: Maybe Bool,
    AppSettings -> Maybe Bool
privacyLinkPreviews :: Maybe Bool,
    AppSettings -> Maybe Bool
privacyShowChatPreviews :: Maybe Bool,
    AppSettings -> Maybe Bool
privacySaveLastDraft :: Maybe Bool,
    AppSettings -> Maybe Bool
privacyProtectScreen :: Maybe Bool,
    AppSettings -> Maybe Int
privacyMediaBlurRadius :: Maybe Int,
    AppSettings -> Maybe NotificationMode
notificationMode :: Maybe NotificationMode,
    AppSettings -> Maybe NotificationPreviewMode
notificationPreviewMode :: Maybe NotificationPreviewMode,
    AppSettings -> Maybe Bool
webrtcPolicyRelay :: Maybe Bool,
    AppSettings -> Maybe [Text]
webrtcICEServers :: Maybe [Text],
    AppSettings -> Maybe Bool
confirmRemoteSessions :: Maybe Bool,
    AppSettings -> Maybe Bool
connectRemoteViaMulticast :: Maybe Bool,
    AppSettings -> Maybe Bool
connectRemoteViaMulticastAuto :: Maybe Bool,
    AppSettings -> Maybe Bool
developerTools :: Maybe Bool,
    AppSettings -> Maybe Bool
confirmDBUpgrades :: Maybe Bool,
    AppSettings -> Maybe LockScreenCalls
androidCallOnLockScreen :: Maybe LockScreenCalls,
    AppSettings -> Maybe Bool
iosCallKitEnabled :: Maybe Bool,
    AppSettings -> Maybe Bool
iosCallKitCallsInRecents :: Maybe Bool,
    AppSettings -> Maybe Double
uiProfileImageCornerRadius :: Maybe Double,
    AppSettings -> Maybe Double
uiChatItemRoundness :: Maybe Double,
    AppSettings -> Maybe Bool
uiChatItemTail :: Maybe Bool,
    AppSettings -> Maybe UIColorScheme
uiColorScheme :: Maybe UIColorScheme,
    AppSettings -> Maybe DarkColorScheme
uiDarkColorScheme :: Maybe DarkColorScheme,
    AppSettings -> Maybe (Map ThemeColorScheme Text)
uiCurrentThemeIds :: Maybe (Map ThemeColorScheme Text),
    AppSettings -> Maybe [UITheme]
uiThemes :: Maybe [UITheme],
    AppSettings -> Maybe Bool
oneHandUI :: Maybe Bool,
    AppSettings -> Maybe Bool
chatBottomBar :: Maybe Bool
  }
  deriving (Int -> AppSettings -> ShowS
[AppSettings] -> ShowS
AppSettings -> String
(Int -> AppSettings -> ShowS)
-> (AppSettings -> String)
-> ([AppSettings] -> ShowS)
-> Show AppSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AppSettings -> ShowS
showsPrec :: Int -> AppSettings -> ShowS
$cshow :: AppSettings -> String
show :: AppSettings -> String
$cshowList :: [AppSettings] -> ShowS
showList :: [AppSettings] -> ShowS
Show)

data NetworkProxy = NetworkProxy
  { NetworkProxy -> Text
host :: Text,
    NetworkProxy -> Int
port :: Int,
    NetworkProxy -> NetworkProxyAuth
auth :: NetworkProxyAuth,
    NetworkProxy -> Text
username :: Text,
    NetworkProxy -> Text
password :: Text
  }
  deriving (Int -> NetworkProxy -> ShowS
[NetworkProxy] -> ShowS
NetworkProxy -> String
(Int -> NetworkProxy -> ShowS)
-> (NetworkProxy -> String)
-> ([NetworkProxy] -> ShowS)
-> Show NetworkProxy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NetworkProxy -> ShowS
showsPrec :: Int -> NetworkProxy -> ShowS
$cshow :: NetworkProxy -> String
show :: NetworkProxy -> String
$cshowList :: [NetworkProxy] -> ShowS
showList :: [NetworkProxy] -> ShowS
Show)

data NetworkProxyAuth = NPAUsername | NPAIsolate
  deriving (Int -> NetworkProxyAuth -> ShowS
[NetworkProxyAuth] -> ShowS
NetworkProxyAuth -> String
(Int -> NetworkProxyAuth -> ShowS)
-> (NetworkProxyAuth -> String)
-> ([NetworkProxyAuth] -> ShowS)
-> Show NetworkProxyAuth
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NetworkProxyAuth -> ShowS
showsPrec :: Int -> NetworkProxyAuth -> ShowS
$cshow :: NetworkProxyAuth -> String
show :: NetworkProxyAuth -> String
$cshowList :: [NetworkProxyAuth] -> ShowS
showList :: [NetworkProxyAuth] -> ShowS
Show)

defaultAppSettings :: AppSettings
defaultAppSettings :: AppSettings
defaultAppSettings =
  AppSettings
    { appPlatform :: Maybe AppPlatform
appPlatform = Maybe AppPlatform
forall a. Maybe a
Nothing,
      networkConfig :: Maybe NetworkConfig
networkConfig = NetworkConfig -> Maybe NetworkConfig
forall a. a -> Maybe a
Just NetworkConfig
defaultNetworkConfig,
      networkProxy :: Maybe NetworkProxy
networkProxy = Maybe NetworkProxy
forall a. Maybe a
Nothing,
      privacyEncryptLocalFiles :: Maybe Bool
privacyEncryptLocalFiles = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      privacyAskToApproveRelays :: Maybe Bool
privacyAskToApproveRelays = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      privacyAcceptImages :: Maybe Bool
privacyAcceptImages = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      privacyLinkPreviews :: Maybe Bool
privacyLinkPreviews = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      privacyShowChatPreviews :: Maybe Bool
privacyShowChatPreviews = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      privacySaveLastDraft :: Maybe Bool
privacySaveLastDraft = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      privacyProtectScreen :: Maybe Bool
privacyProtectScreen = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False,
      privacyMediaBlurRadius :: Maybe Int
privacyMediaBlurRadius = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0,
      notificationMode :: Maybe NotificationMode
notificationMode = NotificationMode -> Maybe NotificationMode
forall a. a -> Maybe a
Just NotificationMode
NMInstant,
      notificationPreviewMode :: Maybe NotificationPreviewMode
notificationPreviewMode = NotificationPreviewMode -> Maybe NotificationPreviewMode
forall a. a -> Maybe a
Just NotificationPreviewMode
NPMMessage,
      webrtcPolicyRelay :: Maybe Bool
webrtcPolicyRelay = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      webrtcICEServers :: Maybe [Text]
webrtcICEServers = [Text] -> Maybe [Text]
forall a. a -> Maybe a
Just [],
      confirmRemoteSessions :: Maybe Bool
confirmRemoteSessions = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False,
      connectRemoteViaMulticast :: Maybe Bool
connectRemoteViaMulticast = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      connectRemoteViaMulticastAuto :: Maybe Bool
connectRemoteViaMulticastAuto = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      developerTools :: Maybe Bool
developerTools = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False,
      confirmDBUpgrades :: Maybe Bool
confirmDBUpgrades = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False,
      androidCallOnLockScreen :: Maybe LockScreenCalls
androidCallOnLockScreen = LockScreenCalls -> Maybe LockScreenCalls
forall a. a -> Maybe a
Just LockScreenCalls
LSCShow,
      iosCallKitEnabled :: Maybe Bool
iosCallKitEnabled = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      iosCallKitCallsInRecents :: Maybe Bool
iosCallKitCallsInRecents = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False,
      uiProfileImageCornerRadius :: Maybe Double
uiProfileImageCornerRadius = Double -> Maybe Double
forall a. a -> Maybe a
Just Double
22.5,
      uiChatItemRoundness :: Maybe Double
uiChatItemRoundness = Double -> Maybe Double
forall a. a -> Maybe a
Just Double
0.75,
      uiChatItemTail :: Maybe Bool
uiChatItemTail = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      uiColorScheme :: Maybe UIColorScheme
uiColorScheme = UIColorScheme -> Maybe UIColorScheme
forall a. a -> Maybe a
Just UIColorScheme
UCSSystem,
      uiDarkColorScheme :: Maybe DarkColorScheme
uiDarkColorScheme = DarkColorScheme -> Maybe DarkColorScheme
forall a. a -> Maybe a
Just DarkColorScheme
DCSSimplex,
      uiCurrentThemeIds :: Maybe (Map ThemeColorScheme Text)
uiCurrentThemeIds = Maybe (Map ThemeColorScheme Text)
forall a. Maybe a
Nothing,
      uiThemes :: Maybe [UITheme]
uiThemes = Maybe [UITheme]
forall a. Maybe a
Nothing,
      oneHandUI :: Maybe Bool
oneHandUI = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True,
      chatBottomBar :: Maybe Bool
chatBottomBar = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
    }

defaultParseAppSettings :: AppSettings
defaultParseAppSettings :: AppSettings
defaultParseAppSettings =
  AppSettings
    { appPlatform :: Maybe AppPlatform
appPlatform = Maybe AppPlatform
forall a. Maybe a
Nothing,
      networkConfig :: Maybe NetworkConfig
networkConfig = Maybe NetworkConfig
forall a. Maybe a
Nothing,
      networkProxy :: Maybe NetworkProxy
networkProxy = Maybe NetworkProxy
forall a. Maybe a
Nothing,
      privacyEncryptLocalFiles :: Maybe Bool
privacyEncryptLocalFiles = Maybe Bool
forall a. Maybe a
Nothing,
      privacyAskToApproveRelays :: Maybe Bool
privacyAskToApproveRelays = Maybe Bool
forall a. Maybe a
Nothing,
      privacyAcceptImages :: Maybe Bool
privacyAcceptImages = Maybe Bool
forall a. Maybe a
Nothing,
      privacyLinkPreviews :: Maybe Bool
privacyLinkPreviews = Maybe Bool
forall a. Maybe a
Nothing,
      privacyShowChatPreviews :: Maybe Bool
privacyShowChatPreviews = Maybe Bool
forall a. Maybe a
Nothing,
      privacySaveLastDraft :: Maybe Bool
privacySaveLastDraft = Maybe Bool
forall a. Maybe a
Nothing,
      privacyProtectScreen :: Maybe Bool
privacyProtectScreen = Maybe Bool
forall a. Maybe a
Nothing,
      privacyMediaBlurRadius :: Maybe Int
privacyMediaBlurRadius = Maybe Int
forall a. Maybe a
Nothing,
      notificationMode :: Maybe NotificationMode
notificationMode = Maybe NotificationMode
forall a. Maybe a
Nothing,
      notificationPreviewMode :: Maybe NotificationPreviewMode
notificationPreviewMode = Maybe NotificationPreviewMode
forall a. Maybe a
Nothing,
      webrtcPolicyRelay :: Maybe Bool
webrtcPolicyRelay = Maybe Bool
forall a. Maybe a
Nothing,
      webrtcICEServers :: Maybe [Text]
webrtcICEServers = Maybe [Text]
forall a. Maybe a
Nothing,
      confirmRemoteSessions :: Maybe Bool
confirmRemoteSessions = Maybe Bool
forall a. Maybe a
Nothing,
      connectRemoteViaMulticast :: Maybe Bool
connectRemoteViaMulticast = Maybe Bool
forall a. Maybe a
Nothing,
      connectRemoteViaMulticastAuto :: Maybe Bool
connectRemoteViaMulticastAuto = Maybe Bool
forall a. Maybe a
Nothing,
      developerTools :: Maybe Bool
developerTools = Maybe Bool
forall a. Maybe a
Nothing,
      confirmDBUpgrades :: Maybe Bool
confirmDBUpgrades = Maybe Bool
forall a. Maybe a
Nothing,
      androidCallOnLockScreen :: Maybe LockScreenCalls
androidCallOnLockScreen = Maybe LockScreenCalls
forall a. Maybe a
Nothing,
      iosCallKitEnabled :: Maybe Bool
iosCallKitEnabled = Maybe Bool
forall a. Maybe a
Nothing,
      iosCallKitCallsInRecents :: Maybe Bool
iosCallKitCallsInRecents = Maybe Bool
forall a. Maybe a
Nothing,
      uiProfileImageCornerRadius :: Maybe Double
uiProfileImageCornerRadius = Maybe Double
forall a. Maybe a
Nothing,
      uiChatItemRoundness :: Maybe Double
uiChatItemRoundness = Maybe Double
forall a. Maybe a
Nothing,
      uiChatItemTail :: Maybe Bool
uiChatItemTail = Maybe Bool
forall a. Maybe a
Nothing,
      uiColorScheme :: Maybe UIColorScheme
uiColorScheme = Maybe UIColorScheme
forall a. Maybe a
Nothing,
      uiDarkColorScheme :: Maybe DarkColorScheme
uiDarkColorScheme = Maybe DarkColorScheme
forall a. Maybe a
Nothing,
      uiCurrentThemeIds :: Maybe (Map ThemeColorScheme Text)
uiCurrentThemeIds = Maybe (Map ThemeColorScheme Text)
forall a. Maybe a
Nothing,
      uiThemes :: Maybe [UITheme]
uiThemes = Maybe [UITheme]
forall a. Maybe a
Nothing,
      oneHandUI :: Maybe Bool
oneHandUI = Maybe Bool
forall a. Maybe a
Nothing,
      chatBottomBar :: Maybe Bool
chatBottomBar = Maybe Bool
forall a. Maybe a
Nothing
    }

combineAppSettings :: AppSettings -> AppSettings -> AppSettings
combineAppSettings :: AppSettings -> AppSettings -> AppSettings
combineAppSettings AppSettings
platformDefaults AppSettings
storedSettings =
  AppSettings
    { appPlatform :: Maybe AppPlatform
appPlatform = (AppSettings -> Maybe AppPlatform) -> Maybe AppPlatform
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe AppPlatform
appPlatform,
      networkConfig :: Maybe NetworkConfig
networkConfig = (AppSettings -> Maybe NetworkConfig) -> Maybe NetworkConfig
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe NetworkConfig
networkConfig,
      networkProxy :: Maybe NetworkProxy
networkProxy = (AppSettings -> Maybe NetworkProxy) -> Maybe NetworkProxy
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe NetworkProxy
networkProxy,
      privacyEncryptLocalFiles :: Maybe Bool
privacyEncryptLocalFiles = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
privacyEncryptLocalFiles,
      privacyAskToApproveRelays :: Maybe Bool
privacyAskToApproveRelays = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
privacyAskToApproveRelays,
      privacyAcceptImages :: Maybe Bool
privacyAcceptImages = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
privacyAcceptImages,
      privacyLinkPreviews :: Maybe Bool
privacyLinkPreviews = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
privacyLinkPreviews,
      privacyShowChatPreviews :: Maybe Bool
privacyShowChatPreviews = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
privacyShowChatPreviews,
      privacySaveLastDraft :: Maybe Bool
privacySaveLastDraft = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
privacySaveLastDraft,
      privacyProtectScreen :: Maybe Bool
privacyProtectScreen = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
privacyProtectScreen,
      privacyMediaBlurRadius :: Maybe Int
privacyMediaBlurRadius = (AppSettings -> Maybe Int) -> Maybe Int
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Int
privacyMediaBlurRadius,
      notificationMode :: Maybe NotificationMode
notificationMode = (AppSettings -> Maybe NotificationMode) -> Maybe NotificationMode
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe NotificationMode
notificationMode,
      notificationPreviewMode :: Maybe NotificationPreviewMode
notificationPreviewMode = (AppSettings -> Maybe NotificationPreviewMode)
-> Maybe NotificationPreviewMode
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe NotificationPreviewMode
notificationPreviewMode,
      webrtcPolicyRelay :: Maybe Bool
webrtcPolicyRelay = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
webrtcPolicyRelay,
      webrtcICEServers :: Maybe [Text]
webrtcICEServers = (AppSettings -> Maybe [Text]) -> Maybe [Text]
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe [Text]
webrtcICEServers,
      confirmRemoteSessions :: Maybe Bool
confirmRemoteSessions = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
confirmRemoteSessions,
      connectRemoteViaMulticast :: Maybe Bool
connectRemoteViaMulticast = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
connectRemoteViaMulticast,
      connectRemoteViaMulticastAuto :: Maybe Bool
connectRemoteViaMulticastAuto = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
connectRemoteViaMulticastAuto,
      developerTools :: Maybe Bool
developerTools = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
developerTools,
      confirmDBUpgrades :: Maybe Bool
confirmDBUpgrades = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
confirmDBUpgrades,
      iosCallKitEnabled :: Maybe Bool
iosCallKitEnabled = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
iosCallKitEnabled,
      iosCallKitCallsInRecents :: Maybe Bool
iosCallKitCallsInRecents = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
iosCallKitCallsInRecents,
      androidCallOnLockScreen :: Maybe LockScreenCalls
androidCallOnLockScreen = (AppSettings -> Maybe LockScreenCalls) -> Maybe LockScreenCalls
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe LockScreenCalls
androidCallOnLockScreen,
      uiProfileImageCornerRadius :: Maybe Double
uiProfileImageCornerRadius = (AppSettings -> Maybe Double) -> Maybe Double
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Double
uiProfileImageCornerRadius,
      uiChatItemRoundness :: Maybe Double
uiChatItemRoundness = (AppSettings -> Maybe Double) -> Maybe Double
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Double
uiChatItemRoundness,
      uiChatItemTail :: Maybe Bool
uiChatItemTail = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
uiChatItemTail,
      uiColorScheme :: Maybe UIColorScheme
uiColorScheme = (AppSettings -> Maybe UIColorScheme) -> Maybe UIColorScheme
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe UIColorScheme
uiColorScheme,
      uiDarkColorScheme :: Maybe DarkColorScheme
uiDarkColorScheme = (AppSettings -> Maybe DarkColorScheme) -> Maybe DarkColorScheme
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe DarkColorScheme
uiDarkColorScheme,
      uiCurrentThemeIds :: Maybe (Map ThemeColorScheme Text)
uiCurrentThemeIds = (AppSettings -> Maybe (Map ThemeColorScheme Text))
-> Maybe (Map ThemeColorScheme Text)
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe (Map ThemeColorScheme Text)
uiCurrentThemeIds,
      uiThemes :: Maybe [UITheme]
uiThemes = (AppSettings -> Maybe [UITheme]) -> Maybe [UITheme]
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe [UITheme]
uiThemes,
      oneHandUI :: Maybe Bool
oneHandUI = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
oneHandUI,
      chatBottomBar :: Maybe Bool
chatBottomBar = (AppSettings -> Maybe Bool) -> Maybe Bool
forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe Bool
chatBottomBar
    }
  where
    p :: (AppSettings -> Maybe a) -> Maybe a
    p :: forall a. (AppSettings -> Maybe a) -> Maybe a
p AppSettings -> Maybe a
sel = AppSettings -> Maybe a
sel AppSettings
storedSettings Maybe a -> Maybe a -> Maybe a
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> AppSettings -> Maybe a
sel AppSettings
platformDefaults Maybe a -> Maybe a -> Maybe a
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> AppSettings -> Maybe a
sel AppSettings
defaultAppSettings

$(JQ.deriveJSON (enumJSON $ dropPrefix "AP") ''AppPlatform)

$(JQ.deriveJSON (enumJSON $ dropPrefix "NM") ''NotificationMode)

$(JQ.deriveJSON (enumJSON $ dropPrefix "NPM") ''NotificationPreviewMode)

$(JQ.deriveJSON (enumJSON $ dropPrefix "LSC") ''LockScreenCalls)

$(JQ.deriveJSON (enumJSON $ dropPrefix "NPA") ''NetworkProxyAuth)

$(JQ.deriveJSON defaultJSON ''NetworkProxy)

$(JQ.deriveToJSON defaultJSON ''AppSettings)

instance FromJSON AppSettings where
  parseJSON :: Value -> Parser AppSettings
parseJSON (J.Object Object
v) = do
    Maybe AppPlatform
appPlatform <- Key -> Parser (Maybe AppPlatform)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"appPlatform"
    Maybe NetworkConfig
networkConfig <- Key -> Parser (Maybe NetworkConfig)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"networkConfig"
    Maybe NetworkProxy
networkProxy <- Key -> Parser (Maybe NetworkProxy)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"networkProxy"
    Maybe Bool
privacyEncryptLocalFiles <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"privacyEncryptLocalFiles"
    Maybe Bool
privacyAskToApproveRelays <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"privacyAskToApproveRelays"
    Maybe Bool
privacyAcceptImages <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"privacyAcceptImages"
    Maybe Bool
privacyLinkPreviews <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"privacyLinkPreviews"
    Maybe Bool
privacyShowChatPreviews <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"privacyShowChatPreviews"
    Maybe Bool
privacySaveLastDraft <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"privacySaveLastDraft"
    Maybe Bool
privacyProtectScreen <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"privacyProtectScreen"
    Maybe Int
privacyMediaBlurRadius <- Key -> Parser (Maybe Int)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"privacyMediaBlurRadius"
    Maybe NotificationMode
notificationMode <- Key -> Parser (Maybe NotificationMode)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"notificationMode"
    Maybe NotificationPreviewMode
notificationPreviewMode <- Key -> Parser (Maybe NotificationPreviewMode)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"notificationPreviewMode"
    Maybe Bool
webrtcPolicyRelay <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"webrtcPolicyRelay"
    Maybe [Text]
webrtcICEServers <- Key -> Parser (Maybe [Text])
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"webrtcICEServers"
    Maybe Bool
confirmRemoteSessions <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"confirmRemoteSessions"
    Maybe Bool
connectRemoteViaMulticast <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"connectRemoteViaMulticast"
    Maybe Bool
connectRemoteViaMulticastAuto <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"connectRemoteViaMulticastAuto"
    Maybe Bool
developerTools <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"developerTools"
    Maybe Bool
confirmDBUpgrades <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"confirmDBUpgrades"
    Maybe Bool
iosCallKitEnabled <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"iosCallKitEnabled"
    Maybe Bool
iosCallKitCallsInRecents <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"iosCallKitCallsInRecents"
    Maybe LockScreenCalls
androidCallOnLockScreen <- Key -> Parser (Maybe LockScreenCalls)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"androidCallOnLockScreen"
    Maybe Double
uiProfileImageCornerRadius <- Key -> Parser (Maybe Double)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"uiProfileImageCornerRadius"
    Maybe Double
uiChatItemRoundness <- Key -> Parser (Maybe Double)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"uiChatItemRoundness"
    Maybe Bool
uiChatItemTail <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"uiChatItemTail"
    Maybe UIColorScheme
uiColorScheme <- Key -> Parser (Maybe UIColorScheme)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"uiColorScheme"
    Maybe DarkColorScheme
uiDarkColorScheme <- Key -> Parser (Maybe DarkColorScheme)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"uiDarkColorScheme"
    Maybe (Map ThemeColorScheme Text)
uiCurrentThemeIds <- Key -> Parser (Maybe (Map ThemeColorScheme Text))
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"uiCurrentThemeIds"
    Maybe [UITheme]
uiThemes <- Key -> Parser (Maybe [UITheme])
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"uiThemes"
    Maybe Bool
oneHandUI <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"oneHandUI"
    Maybe Bool
chatBottomBar <- Key -> Parser (Maybe Bool)
forall {a}. FromJSON a => Key -> Parser (Maybe a)
p Key
"chatBottomBar"
    AppSettings -> Parser AppSettings
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      AppSettings
        { Maybe AppPlatform
appPlatform :: Maybe AppPlatform
appPlatform :: Maybe AppPlatform
appPlatform,
          Maybe NetworkConfig
networkConfig :: Maybe NetworkConfig
networkConfig :: Maybe NetworkConfig
networkConfig,
          Maybe NetworkProxy
networkProxy :: Maybe NetworkProxy
networkProxy :: Maybe NetworkProxy
networkProxy,
          Maybe Bool
privacyEncryptLocalFiles :: Maybe Bool
privacyEncryptLocalFiles :: Maybe Bool
privacyEncryptLocalFiles,
          Maybe Bool
privacyAskToApproveRelays :: Maybe Bool
privacyAskToApproveRelays :: Maybe Bool
privacyAskToApproveRelays,
          Maybe Bool
privacyAcceptImages :: Maybe Bool
privacyAcceptImages :: Maybe Bool
privacyAcceptImages,
          Maybe Bool
privacyLinkPreviews :: Maybe Bool
privacyLinkPreviews :: Maybe Bool
privacyLinkPreviews,
          Maybe Bool
privacyShowChatPreviews :: Maybe Bool
privacyShowChatPreviews :: Maybe Bool
privacyShowChatPreviews,
          Maybe Bool
privacySaveLastDraft :: Maybe Bool
privacySaveLastDraft :: Maybe Bool
privacySaveLastDraft,
          Maybe Bool
privacyProtectScreen :: Maybe Bool
privacyProtectScreen :: Maybe Bool
privacyProtectScreen,
          Maybe Int
privacyMediaBlurRadius :: Maybe Int
privacyMediaBlurRadius :: Maybe Int
privacyMediaBlurRadius,
          Maybe NotificationMode
notificationMode :: Maybe NotificationMode
notificationMode :: Maybe NotificationMode
notificationMode,
          Maybe NotificationPreviewMode
notificationPreviewMode :: Maybe NotificationPreviewMode
notificationPreviewMode :: Maybe NotificationPreviewMode
notificationPreviewMode,
          Maybe Bool
webrtcPolicyRelay :: Maybe Bool
webrtcPolicyRelay :: Maybe Bool
webrtcPolicyRelay,
          Maybe [Text]
webrtcICEServers :: Maybe [Text]
webrtcICEServers :: Maybe [Text]
webrtcICEServers,
          Maybe Bool
confirmRemoteSessions :: Maybe Bool
confirmRemoteSessions :: Maybe Bool
confirmRemoteSessions,
          Maybe Bool
connectRemoteViaMulticast :: Maybe Bool
connectRemoteViaMulticast :: Maybe Bool
connectRemoteViaMulticast,
          Maybe Bool
connectRemoteViaMulticastAuto :: Maybe Bool
connectRemoteViaMulticastAuto :: Maybe Bool
connectRemoteViaMulticastAuto,
          Maybe Bool
developerTools :: Maybe Bool
developerTools :: Maybe Bool
developerTools,
          Maybe Bool
confirmDBUpgrades :: Maybe Bool
confirmDBUpgrades :: Maybe Bool
confirmDBUpgrades,
          Maybe Bool
iosCallKitEnabled :: Maybe Bool
iosCallKitEnabled :: Maybe Bool
iosCallKitEnabled,
          Maybe Bool
iosCallKitCallsInRecents :: Maybe Bool
iosCallKitCallsInRecents :: Maybe Bool
iosCallKitCallsInRecents,
          Maybe LockScreenCalls
androidCallOnLockScreen :: Maybe LockScreenCalls
androidCallOnLockScreen :: Maybe LockScreenCalls
androidCallOnLockScreen,
          Maybe Double
uiProfileImageCornerRadius :: Maybe Double
uiProfileImageCornerRadius :: Maybe Double
uiProfileImageCornerRadius,
          Maybe Double
uiChatItemRoundness :: Maybe Double
uiChatItemRoundness :: Maybe Double
uiChatItemRoundness,
          Maybe Bool
uiChatItemTail :: Maybe Bool
uiChatItemTail :: Maybe Bool
uiChatItemTail,
          Maybe UIColorScheme
uiColorScheme :: Maybe UIColorScheme
uiColorScheme :: Maybe UIColorScheme
uiColorScheme,
          Maybe DarkColorScheme
uiDarkColorScheme :: Maybe DarkColorScheme
uiDarkColorScheme :: Maybe DarkColorScheme
uiDarkColorScheme,
          Maybe (Map ThemeColorScheme Text)
uiCurrentThemeIds :: Maybe (Map ThemeColorScheme Text)
uiCurrentThemeIds :: Maybe (Map ThemeColorScheme Text)
uiCurrentThemeIds,
          Maybe [UITheme]
uiThemes :: Maybe [UITheme]
uiThemes :: Maybe [UITheme]
uiThemes,
          Maybe Bool
oneHandUI :: Maybe Bool
oneHandUI :: Maybe Bool
oneHandUI,
          Maybe Bool
chatBottomBar :: Maybe Bool
chatBottomBar :: Maybe Bool
chatBottomBar
        }
    where
      p :: Key -> Parser (Maybe a)
p Key
key = Object
v Object -> Key -> Parser (Maybe a)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
key Parser (Maybe a) -> Parser (Maybe a) -> Parser (Maybe a)
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe a -> Parser (Maybe a)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing
  parseJSON Value
_ = AppSettings -> Parser AppSettings
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AppSettings
defaultParseAppSettings

readAppSettings :: FilePath -> Maybe AppSettings -> IO AppSettings
readAppSettings :: String -> Maybe AppSettings -> IO AppSettings
readAppSettings String
f Maybe AppSettings
platformDefaults =
  AppSettings -> AppSettings -> AppSettings
combineAppSettings (AppSettings -> Maybe AppSettings -> AppSettings
forall a. a -> Maybe a -> a
fromMaybe AppSettings
defaultAppSettings Maybe AppSettings
platformDefaults) (AppSettings -> AppSettings)
-> (Maybe AppSettings -> AppSettings)
-> Maybe AppSettings
-> AppSettings
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AppSettings -> Maybe AppSettings -> AppSettings
forall a. a -> Maybe a -> a
fromMaybe AppSettings
defaultParseAppSettings
    (Maybe AppSettings -> AppSettings)
-> IO (Maybe AppSettings) -> IO AppSettings
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> IO (Maybe AppSettings)
forall a. FromJSON a => String -> IO (Maybe a)
J.decodeFileStrict String
f IO (Maybe AppSettings)
-> IO (Maybe AppSettings) -> IO (Maybe AppSettings)
forall a. IO a -> IO a -> IO a
`catchAll_` Maybe AppSettings -> IO (Maybe AppSettings)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe AppSettings
forall a. Maybe a
Nothing)