diff --git a/package.yaml b/package.yaml index f90fdd4d5..c3adbcd69 100644 --- a/package.yaml +++ b/package.yaml @@ -39,6 +39,7 @@ dependencies: - socks == 0.6.* - sqlcipher-simple == 0.4.* - stm == 2.5.* + - template-haskell == 2.16.* - terminal == 0.2.* - text == 1.2.* - time == 1.9.* diff --git a/simplex-chat.cabal b/simplex-chat.cabal index f07e6260a..420e8a3af 100644 --- a/simplex-chat.cabal +++ b/simplex-chat.cabal @@ -125,6 +125,7 @@ library , socks ==0.6.* , sqlcipher-simple ==0.4.* , stm ==2.5.* + , template-haskell ==2.16.* , terminal ==0.2.* , text ==1.2.* , time ==1.9.* @@ -171,6 +172,7 @@ executable simplex-bot , socks ==0.6.* , sqlcipher-simple ==0.4.* , stm ==2.5.* + , template-haskell ==2.16.* , terminal ==0.2.* , text ==1.2.* , time ==1.9.* @@ -217,6 +219,7 @@ executable simplex-bot-advanced , socks ==0.6.* , sqlcipher-simple ==0.4.* , stm ==2.5.* + , template-haskell ==2.16.* , terminal ==0.2.* , text ==1.2.* , time ==1.9.* @@ -264,6 +267,7 @@ executable simplex-chat , socks ==0.6.* , sqlcipher-simple ==0.4.* , stm ==2.5.* + , template-haskell ==2.16.* , terminal ==0.2.* , text ==1.2.* , time ==1.9.* @@ -320,6 +324,7 @@ test-suite simplex-chat-test , socks ==0.6.* , sqlcipher-simple ==0.4.* , stm ==2.5.* + , template-haskell ==2.16.* , terminal ==0.2.* , text ==1.2.* , time ==1.9.* diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index b29051670..073903d0c 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -8,6 +8,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} @@ -1222,7 +1223,7 @@ processChatCommand = \case updateGroupProfileByName gName $ \p -> p {groupPreferences = Just . setGroupPreference' SGFTimedMessages pref $ groupPreferences p} QuitChat -> liftIO exitSuccess - ShowVersion -> pure $ CRVersionInfo versionNumber + ShowVersion -> pure $ CRVersionInfo versionNumber CoreVersionInfo {buildTimestamp = $(buildTimestampQ)} DebugLocks -> do chatLockName <- atomically . tryReadTMVar =<< asks chatLock agentLocks <- withAgent debugAgentLocks diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index d95dcdf1d..43a9101ec 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -4,10 +4,10 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE StrictData #-} +{-# LANGUAGE TemplateHaskell #-} module Simplex.Chat.Controller where @@ -30,9 +30,11 @@ import Data.Map.Strict (Map) import Data.String import Data.Text (Text) import Data.Time (ZonedTime) -import Data.Time.Clock (UTCTime) +import Data.Time.Clock (UTCTime, getCurrentTime) +import Data.Time.Format (defaultTimeLocale, formatTime, iso8601DateFormat) import Data.Version (showVersion) import GHC.Generics (Generic) +import Language.Haskell.TH (Exp, Q, runIO) import Numeric.Natural import qualified Paths_simplex_chat as SC import Simplex.Chat.Call @@ -67,6 +69,11 @@ versionStr = "SimpleX Chat v" <> versionNumber updateStr :: String updateStr = "To update run: curl -o- https://raw.githubusercontent.com/simplex-chat/simplex-chat/master/install.sh | bash" +buildTimestampQ :: Q Exp +buildTimestampQ = do + s <- formatTime defaultTimeLocale (iso8601DateFormat $ Just "%H:%M:%S") <$> runIO getCurrentTime + [|fromString s|] + data ChatConfig = ChatConfig { agentConfig :: AgentConfig, yesToMigrations :: Bool, @@ -337,7 +344,7 @@ data ChatResponse | CRFileTransferStatus (FileTransfer, [Integer]) -- TODO refactor this type to FileTransferStatus | CRUserProfile {profile :: Profile} | CRUserProfileNoChange - | CRVersionInfo {version :: String} + | CRVersionInfo {version :: String, versionInfo :: CoreVersionInfo} | CRInvitation {connReqInvitation :: ConnReqInvitation} | CRSentConfirmation | CRSentInvitation {customUserProfile :: Maybe Profile} @@ -549,6 +556,13 @@ tmeToPref currentTTL tme = uncurry TimedMessagesPreference $ case tme of data ChatLogLevel = CLLDebug | CLLInfo | CLLWarning | CLLError | CLLImportant deriving (Eq, Ord, Show) +data CoreVersionInfo = CoreVersionInfo + { buildTimestamp :: String + } + deriving (Show, Generic) + +instance ToJSON CoreVersionInfo where toEncoding = J.genericToEncoding J.defaultOptions + data ChatError = ChatError {errorType :: ChatErrorType} | ChatErrorAgent {agentError :: AgentErrorType, connectionEntity_ :: Maybe ConnectionEntity} diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 1ca8c9e53..69b260145 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -112,7 +112,7 @@ responseToView user_ ChatConfig {logLevel, testView} liveItems ts = \case CRFileTransferStatus ftStatus -> viewFileTransferStatus ftStatus CRUserProfile p -> viewUserProfile p CRUserProfileNoChange -> ["user profile did not change"] - CRVersionInfo _ -> [plain versionStr, plain updateStr] + CRVersionInfo _ _ -> [plain versionStr, plain updateStr] CRChatCmdError e -> viewChatError logLevel e CRInvitation cReq -> viewConnReqInvitation cReq CRSentConfirmation -> ["confirmation sent!"]