core: update version response (#1819)

* core: update version response

* add simplexmq commit and version to version info

* refactor
This commit is contained in:
Evgeny Poberezkin
2023-01-22 15:16:45 +00:00
committed by GitHub
parent 8ff8f9d695
commit 114b76e3f8
5 changed files with 46 additions and 9 deletions
+31 -4
View File
@@ -55,6 +55,7 @@ import Simplex.Messaging.Notifications.Protocol (DeviceToken (..), NtfTknStatus)
import Simplex.Messaging.Parsers (dropPrefix, enumJSON, parseAll, parseString, sumTypeJSON)
import Simplex.Messaging.Protocol (AProtocolType, CorrId, MsgFlags)
import Simplex.Messaging.TMap (TMap)
import Simplex.Messaging.Transport (simplexMQVersion)
import Simplex.Messaging.Transport.Client (TransportHost)
import System.IO (Handle)
import System.Mem.Weak (Weak)
@@ -63,8 +64,8 @@ import UnliftIO.STM
versionNumber :: String
versionNumber = showVersion SC.version
versionStr :: String
versionStr = "SimpleX Chat v" <> versionNumber
versionString :: String -> String
versionString version = "SimpleX Chat v" <> version
updateStr :: String
updateStr = "To update run: curl -o- https://raw.githubusercontent.com/simplex-chat/simplex-chat/master/install.sh | bash"
@@ -74,6 +75,29 @@ buildTimestampQ = do
s <- formatTime defaultTimeLocale (iso8601DateFormat $ Just "%H:%M:%S") <$> runIO getCurrentTime
[|fromString s|]
simplexmqCommitQ :: Q Exp
simplexmqCommitQ = do
s <- either error B.unpack . A.parseOnly commitHashP <$> runIO (B.readFile "./cabal.project")
[|fromString s|]
where
commitHashP :: A.Parser ByteString
commitHashP =
A.manyTill' A.anyChar "location: https://github.com/simplex-chat/simplexmq.git"
*> A.takeWhile (== ' ')
*> A.endOfLine
*> A.takeWhile (== ' ')
*> "tag: "
*> A.takeWhile (A.notInClass " \r\n")
coreVersionInfo :: String -> String -> CoreVersionInfo
coreVersionInfo buildTimestamp simplexmqCommit =
CoreVersionInfo
{ version = versionNumber,
buildTimestamp,
simplexmqVersion = simplexMQVersion,
simplexmqCommit
}
data ChatConfig = ChatConfig
{ agentConfig :: AgentConfig,
yesToMigrations :: Bool,
@@ -344,7 +368,7 @@ data ChatResponse
| CRFileTransferStatus (FileTransfer, [Integer]) -- TODO refactor this type to FileTransferStatus
| CRUserProfile {profile :: Profile}
| CRUserProfileNoChange
| CRVersionInfo {version :: String, versionInfo :: CoreVersionInfo}
| CRVersionInfo {versionInfo :: CoreVersionInfo}
| CRInvitation {connReqInvitation :: ConnReqInvitation}
| CRSentConfirmation
| CRSentInvitation {customUserProfile :: Maybe Profile}
@@ -557,7 +581,10 @@ data ChatLogLevel = CLLDebug | CLLInfo | CLLWarning | CLLError | CLLImportant
deriving (Eq, Ord, Show)
data CoreVersionInfo = CoreVersionInfo
{ buildTimestamp :: String
{ version :: String,
buildTimestamp :: String,
simplexmqVersion :: String,
simplexmqCommit :: String
}
deriving (Show, Generic)