2021-06-25 18:34:29 +01:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
2021-06-25 18:18:24 +01:00
|
|
|
|
|
|
|
module Main where
|
|
|
|
|
2022-04-10 16:30:54 +01:00
|
|
|
import Control.Concurrent (threadDelay)
|
2022-05-13 19:44:03 +01:00
|
|
|
import Server
|
2022-04-10 17:13:06 +01:00
|
|
|
import Simplex.Chat.Controller (versionNumber)
|
|
|
|
import Simplex.Chat.Core
|
2021-07-05 20:05:07 +01:00
|
|
|
import Simplex.Chat.Options
|
2022-01-21 11:09:33 +00:00
|
|
|
import Simplex.Chat.Terminal
|
2022-04-10 16:30:54 +01:00
|
|
|
import Simplex.Chat.View (serializeChatResponse)
|
2021-06-25 18:34:29 +01:00
|
|
|
import System.Directory (getAppUserDataDirectory)
|
2021-07-07 22:46:38 +01:00
|
|
|
import System.Terminal (withTerminal)
|
2021-06-25 18:34:29 +01:00
|
|
|
|
2021-06-25 18:18:24 +01:00
|
|
|
main :: IO ()
|
|
|
|
main = do
|
2021-06-25 18:34:29 +01:00
|
|
|
appDir <- getAppUserDataDirectory "simplex"
|
2022-05-13 19:44:03 +01:00
|
|
|
opts@ChatOpts {chatCmd, chatServerPort} <- getChatOpts appDir "simplex_v1"
|
2022-04-10 16:30:54 +01:00
|
|
|
if null chatCmd
|
2022-05-13 19:44:03 +01:00
|
|
|
then case chatServerPort of
|
|
|
|
Just chatPort ->
|
|
|
|
simplexChatServer defaultChatServerConfig {chatPort} terminalChatConfig opts
|
|
|
|
_ -> do
|
|
|
|
welcome opts
|
|
|
|
t <- withTerminal pure
|
|
|
|
simplexChatTerminal terminalChatConfig opts t
|
2022-05-11 16:52:08 +01:00
|
|
|
else simplexChatCore terminalChatConfig opts Nothing $ \_ cc -> do
|
2022-04-10 17:13:06 +01:00
|
|
|
r <- sendChatCmd cc chatCmd
|
2022-04-10 16:30:54 +01:00
|
|
|
putStrLn $ serializeChatResponse r
|
|
|
|
threadDelay $ chatCmdDelay opts * 1000000
|
|
|
|
|
|
|
|
welcome :: ChatOpts -> IO ()
|
|
|
|
welcome ChatOpts {dbFilePrefix} = do
|
2021-11-07 21:57:05 +00:00
|
|
|
putStrLn $ "SimpleX Chat v" ++ versionNumber
|
2022-01-21 11:09:33 +00:00
|
|
|
putStrLn $ "db: " <> dbFilePrefix <> "_chat.db, " <> dbFilePrefix <> "_agent.db"
|
2021-06-25 18:34:29 +01:00
|
|
|
putStrLn "type \"/help\" or \"/h\" for usage info"
|