diff options
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index d6f2de7e..7cfbdd4e 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs | |||
@@ -21,6 +21,11 @@ import Data.Word | |||
21 | import GHC.Conc (unsafeIOToSTM) | 21 | import GHC.Conc (unsafeIOToSTM) |
22 | import qualified Data.Set as Set | 22 | import qualified Data.Set as Set |
23 | import qualified Data.Array.Unboxed as A | 23 | import qualified Data.Array.Unboxed as A |
24 | import SensibleDir | ||
25 | import System.FilePath | ||
26 | import System.IO.Temp | ||
27 | import System.Environment | ||
28 | import System.Directory | ||
24 | 29 | ||
25 | -- util, todo: move to another module | 30 | -- util, todo: move to another module |
26 | maybeToEither :: Maybe b -> Either String b | 31 | maybeToEither :: Maybe b -> Either String b |
@@ -38,6 +43,7 @@ type MsgTypeArray = A.UArray Word8 Word16 | |||
38 | 43 | ||
39 | -- | Information, that may be made visible in multiple sessions, as well | 44 | -- | Information, that may be made visible in multiple sessions, as well |
40 | -- as displayed in some way to the user via mutiple views. | 45 | -- as displayed in some way to the user via mutiple views. |
46 | -- | ||
41 | data SessionView = SessionView | 47 | data SessionView = SessionView |
42 | { svNick :: TVar ByteString | 48 | { svNick :: TVar ByteString |
43 | , svStatus :: TVar UserStatus | 49 | , svStatus :: TVar UserStatus |
@@ -45,8 +51,9 @@ data SessionView = SessionView | |||
45 | , svGroups :: TVar (Map.Map GroupChatId (Set.Set SockAddr)) | 51 | , svGroups :: TVar (Map.Map GroupChatId (Set.Set SockAddr)) |
46 | , svCacheDir :: FilePath -- ^ directory path used if the session has to use the disk for cache | 52 | , svCacheDir :: FilePath -- ^ directory path used if the session has to use the disk for cache |
47 | -- clean up only if space is needed | 53 | -- clean up only if space is needed |
48 | , svTmpDir :: FilePath -- Once off storage goes here, should clean up quickly | 54 | , svTmpDir :: FilePath -- ^ Once off storage goes here, should clean up quickly |
49 | , svConfigDir :: FilePath -- profile related storage, etc, never clean up | 55 | , svConfigDir :: FilePath -- ^ profile related storage, etc, never clean up |
56 | , svDownloadDir :: TVar FilePath -- ^ where to put files the user downloads | ||
50 | } | 57 | } |
51 | 58 | ||
52 | 59 | ||
@@ -88,11 +95,25 @@ newSessionsState crypto unrechook hooks = do | |||
88 | status <- atomically $ newTVar Online | 95 | status <- atomically $ newTVar Online |
89 | statusmsg <- atomically $ newTVar B.empty | 96 | statusmsg <- atomically $ newTVar B.empty |
90 | grps <- atomically $ newTVar Map.empty | 97 | grps <- atomically $ newTVar Map.empty |
98 | pname <- getProgName | ||
99 | cachedir <- sensibleCacheDirCreateIfMissing pname | ||
100 | tmpdir <- (</> pname) <$> getCanonicalTemporaryDirectory | ||
101 | configdir <- sensibleVarLib pname | ||
102 | homedir <- getHomeDirectory | ||
103 | svDownloadDir0 <- atomically $ newTVar (homedir </> "Downloads") | ||
91 | return NCSessions { netCryptoSessions = x | 104 | return NCSessions { netCryptoSessions = x |
92 | , transportCrypto = crypto | 105 | , transportCrypto = crypto |
93 | , defaultHooks = hooks | 106 | , defaultHooks = hooks |
94 | , defaultUnrecognizedHook = unrechook | 107 | , defaultUnrecognizedHook = unrechook |
95 | , sessionView = SessionView { svNick = nick, svStatus = status, svStatusMsg = statusmsg, svGroups = grps } | 108 | , sessionView = SessionView { svNick = nick |
109 | , svStatus = status | ||
110 | , svStatusMsg = statusmsg | ||
111 | , svGroups = grps | ||
112 | , svCacheDir = cachedir | ||
113 | , svTmpDir = tmpdir | ||
114 | , svConfigDir = configdir | ||
115 | , svDownloadDir = svDownloadDir0 | ||
116 | } | ||
96 | , msgTypeArray = allMsgTypes -- todo make this a parameter | 117 | , msgTypeArray = allMsgTypes -- todo make this a parameter |
97 | } | 118 | } |
98 | 119 | ||