cli: set device name for remote control via CLI option (#3427)

* cli: set device name for remote control via CLI option

* fix

* add property in tests
This commit is contained in:
Evgeny Poberezkin 2023-11-22 22:11:32 +00:00 committed by GitHub
parent 4af4fbae2b
commit 2d4e99d610
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 6 deletions

View File

@ -74,6 +74,7 @@ mkChatOpts :: BroadcastBotOpts -> ChatOpts
mkChatOpts BroadcastBotOpts {coreOptions} = mkChatOpts BroadcastBotOpts {coreOptions} =
ChatOpts ChatOpts
{ coreOptions, { coreOptions,
deviceName = Nothing,
chatCmd = "", chatCmd = "",
chatCmdDelay = 3, chatCmdDelay = 3,
chatServerPort = Nothing, chatServerPort = Nothing,

View File

@ -72,6 +72,7 @@ mkChatOpts :: DirectoryOpts -> ChatOpts
mkChatOpts DirectoryOpts {coreOptions} = mkChatOpts DirectoryOpts {coreOptions} =
ChatOpts ChatOpts
{ coreOptions, { coreOptions,
deviceName = Nothing,
chatCmd = "", chatCmd = "",
chatCmdDelay = 3, chatCmdDelay = 3,
chatServerPort = Nothing, chatServerPort = Nothing,

View File

@ -153,7 +153,8 @@ defaultChatConfig =
cleanupManagerStepDelay = 3 * 1000000, -- 3 seconds cleanupManagerStepDelay = 3 * 1000000, -- 3 seconds
ciExpirationInterval = 30 * 60 * 1000000, -- 30 minutes ciExpirationInterval = 30 * 60 * 1000000, -- 30 minutes
coreApi = False, coreApi = False,
highlyAvailable = False highlyAvailable = False,
deviceNameForRemote = ""
} }
_defaultSMPServers :: NonEmpty SMPServerWithAuth _defaultSMPServers :: NonEmpty SMPServerWithAuth
@ -197,7 +198,7 @@ createChatDatabase filePrefix key confirmMigrations = runExceptT $ do
pure ChatDatabase {chatStore, agentStore} pure ChatDatabase {chatStore, agentStore}
newChatController :: ChatDatabase -> Maybe User -> ChatConfig -> ChatOpts -> IO ChatController newChatController :: ChatDatabase -> Maybe User -> ChatConfig -> ChatOpts -> IO ChatController
newChatController ChatDatabase {chatStore, agentStore} user cfg@ChatConfig {agentConfig = aCfg, defaultServers, inlineFiles, tempDir} ChatOpts {coreOptions = CoreChatOpts {smpServers, xftpServers, networkConfig, logLevel, logConnections, logServerHosts, logFile, tbqSize, highlyAvailable}, optFilesFolder, showReactions, allowInstantFiles, autoAcceptFileSize} = do newChatController ChatDatabase {chatStore, agentStore} user cfg@ChatConfig {agentConfig = aCfg, defaultServers, inlineFiles, tempDir, deviceNameForRemote} ChatOpts {coreOptions = CoreChatOpts {smpServers, xftpServers, networkConfig, logLevel, logConnections, logServerHosts, logFile, tbqSize, highlyAvailable}, deviceName, optFilesFolder, showReactions, allowInstantFiles, autoAcceptFileSize} = do
let inlineFiles' = if allowInstantFiles || autoAcceptFileSize > 0 then inlineFiles else inlineFiles {sendChunks = 0, receiveInstant = False} let inlineFiles' = if allowInstantFiles || autoAcceptFileSize > 0 then inlineFiles else inlineFiles {sendChunks = 0, receiveInstant = False}
config = cfg {logLevel, showReactions, tbqSize, subscriptionEvents = logConnections, hostEvents = logServerHosts, defaultServers = configServers, inlineFiles = inlineFiles', autoAcceptFileSize, highlyAvailable} config = cfg {logLevel, showReactions, tbqSize, subscriptionEvents = logConnections, hostEvents = logServerHosts, defaultServers = configServers, inlineFiles = inlineFiles', autoAcceptFileSize, highlyAvailable}
firstTime = dbNew chatStore firstTime = dbNew chatStore
@ -215,7 +216,7 @@ newChatController ChatDatabase {chatStore, agentStore} user cfg@ChatConfig {agen
sndFiles <- newTVarIO M.empty sndFiles <- newTVarIO M.empty
rcvFiles <- newTVarIO M.empty rcvFiles <- newTVarIO M.empty
currentCalls <- atomically TM.empty currentCalls <- atomically TM.empty
localDeviceName <- newTVarIO "" -- TODO set in config localDeviceName <- newTVarIO $ fromMaybe deviceNameForRemote deviceName
multicastSubscribers <- newTMVarIO 0 multicastSubscribers <- newTMVarIO 0
remoteSessionSeq <- newTVarIO 0 remoteSessionSeq <- newTVarIO 0
remoteHostSessions <- atomically TM.empty remoteHostSessions <- atomically TM.empty

View File

@ -135,7 +135,8 @@ data ChatConfig = ChatConfig
cleanupManagerStepDelay :: Int64, cleanupManagerStepDelay :: Int64,
ciExpirationInterval :: Int64, -- microseconds ciExpirationInterval :: Int64, -- microseconds
coreApi :: Bool, coreApi :: Bool,
highlyAvailable :: Bool highlyAvailable :: Bool,
deviceNameForRemote :: Text
} }
data DefaultAgentServers = DefaultAgentServers data DefaultAgentServers = DefaultAgentServers

View File

@ -181,6 +181,7 @@ mobileChatOpts dbFilePrefix dbKey =
tbqSize = 1024, tbqSize = 1024,
highlyAvailable = False highlyAvailable = False
}, },
deviceName = Nothing,
chatCmd = "", chatCmd = "",
chatCmdDelay = 3, chatCmdDelay = 3,
chatServerPort = Nothing, chatServerPort = Nothing,
@ -197,7 +198,8 @@ defaultMobileConfig =
defaultChatConfig defaultChatConfig
{ confirmMigrations = MCYesUp, { confirmMigrations = MCYesUp,
logLevel = CLLError, logLevel = CLLError,
coreApi = True coreApi = True,
deviceNameForRemote = "Mobile"
} }
getActiveUser_ :: SQLiteStore -> IO (Maybe User) getActiveUser_ :: SQLiteStore -> IO (Maybe User)

View File

@ -19,6 +19,7 @@ where
import Control.Logger.Simple (LogLevel (..)) import Control.Logger.Simple (LogLevel (..))
import qualified Data.Attoparsec.ByteString.Char8 as A import qualified Data.Attoparsec.ByteString.Char8 as A
import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Char8 as B
import Data.Text (Text)
import Numeric.Natural (Natural) import Numeric.Natural (Natural)
import Options.Applicative import Options.Applicative
import Simplex.Chat.Controller (ChatLogLevel (..), updateStr, versionNumber, versionString) import Simplex.Chat.Controller (ChatLogLevel (..), updateStr, versionNumber, versionString)
@ -32,6 +33,7 @@ import System.FilePath (combine)
data ChatOpts = ChatOpts data ChatOpts = ChatOpts
{ coreOptions :: CoreChatOpts, { coreOptions :: CoreChatOpts,
deviceName :: Maybe Text,
chatCmd :: String, chatCmd :: String,
chatCmdDelay :: Int, chatCmdDelay :: Int,
chatServerPort :: Maybe String, chatServerPort :: Maybe String,
@ -200,6 +202,14 @@ coreChatOptsP appDir defaultDbFileName = do
chatOptsP :: FilePath -> FilePath -> Parser ChatOpts chatOptsP :: FilePath -> FilePath -> Parser ChatOpts
chatOptsP appDir defaultDbFileName = do chatOptsP appDir defaultDbFileName = do
coreOptions <- coreChatOptsP appDir defaultDbFileName coreOptions <- coreChatOptsP appDir defaultDbFileName
deviceName <-
optional $
strOption
( long "device-name"
<> short 'e'
<> metavar "DEVICE"
<> help "Device name to use in connections with remote hosts and controller"
)
chatCmd <- chatCmd <-
strOption strOption
( long "execute" ( long "execute"
@ -268,6 +278,7 @@ chatOptsP appDir defaultDbFileName = do
pure pure
ChatOpts ChatOpts
{ coreOptions, { coreOptions,
deviceName,
chatCmd, chatCmd,
chatCmdDelay, chatCmdDelay,
chatServerPort, chatServerPort,

View File

@ -35,7 +35,8 @@ terminalChatConfig =
ntf = ["ntf://FB-Uop7RTaZZEG0ZLD2CIaTjsPh-Fw0zFAnb7QyA8Ks=@ntf2.simplex.im,ntg7jdjy2i3qbib3sykiho3enekwiaqg3icctliqhtqcg6jmoh6cxiad.onion"], ntf = ["ntf://FB-Uop7RTaZZEG0ZLD2CIaTjsPh-Fw0zFAnb7QyA8Ks=@ntf2.simplex.im,ntg7jdjy2i3qbib3sykiho3enekwiaqg3icctliqhtqcg6jmoh6cxiad.onion"],
xftp = defaultXFTPServers, xftp = defaultXFTPServers,
netCfg = defaultNetworkConfig netCfg = defaultNetworkConfig
} },
deviceNameForRemote = "SimpleX CLI"
} }
simplexChatTerminal :: WithTerminal t => ChatConfig -> ChatOpts -> t -> IO () simplexChatTerminal :: WithTerminal t => ChatConfig -> ChatOpts -> t -> IO ()

View File

@ -74,6 +74,7 @@ testOpts =
tbqSize = 16, tbqSize = 16,
highlyAvailable = False highlyAvailable = False
}, },
deviceName = Nothing,
chatCmd = "", chatCmd = "",
chatCmdDelay = 3, chatCmdDelay = 3,
chatServerPort = Nothing, chatServerPort = Nothing,