Merge branch 'stable' into stable-android
This commit is contained in:
commit
cb52d75ff0
@ -91,11 +91,11 @@ class MainActivity: FragmentActivity() {
|
|||||||
// When pressed Back and there is no one wants to process the back event, clear auth state to force re-auth on launch
|
// When pressed Back and there is no one wants to process the back event, clear auth state to force re-auth on launch
|
||||||
AppLock.clearAuthState()
|
AppLock.clearAuthState()
|
||||||
AppLock.laFailed.value = true
|
AppLock.laFailed.value = true
|
||||||
AppLock.destroyedAfterBackPress.value = true
|
|
||||||
}
|
}
|
||||||
if (!onBackPressedDispatcher.hasEnabledCallbacks()) {
|
if (!onBackPressedDispatcher.hasEnabledCallbacks()) {
|
||||||
// Drop shared content
|
// Drop shared content
|
||||||
SimplexApp.context.chatModel.sharedContent.value = null
|
SimplexApp.context.chatModel.sharedContent.value = null
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,3 +69,5 @@ actual fun hideKeyboard(view: Any?) {
|
|||||||
(androidAppContext.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(view.windowToken, 0)
|
(androidAppContext.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(view.windowToken, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actual fun androidIsFinishingMainActivity(): Boolean = (mainActivity.get()?.isFinishing == true)
|
||||||
|
@ -149,7 +149,7 @@ fun MainScreen() {
|
|||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
// With these constrains when user presses back button while on ChatList, activity destroys and shows auth request
|
// With these constrains when user presses back button while on ChatList, activity destroys and shows auth request
|
||||||
// while the screen moves to a launcher. Detect it and prevent showing the auth
|
// while the screen moves to a launcher. Detect it and prevent showing the auth
|
||||||
if (!(AppLock.destroyedAfterBackPress.value && chatModel.controller.appPrefs.laMode.get() == LAMode.SYSTEM)) {
|
if (!(androidIsFinishingMainActivity() && chatModel.controller.appPrefs.laMode.get() == LAMode.SYSTEM)) {
|
||||||
AppLock.runAuthenticate()
|
AppLock.runAuthenticate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ object AppLock {
|
|||||||
|
|
||||||
// Remember result and show it after orientation change
|
// Remember result and show it after orientation change
|
||||||
val laFailed = mutableStateOf(false)
|
val laFailed = mutableStateOf(false)
|
||||||
val destroyedAfterBackPress = mutableStateOf(false)
|
|
||||||
|
|
||||||
fun clearAuthState() {
|
fun clearAuthState() {
|
||||||
userAuthorized.value = null
|
userAuthorized.value = null
|
||||||
|
@ -14,3 +14,5 @@ expect fun LocalMultiplatformView(): Any?
|
|||||||
@Composable
|
@Composable
|
||||||
expect fun getKeyboardState(): State<KeyboardState>
|
expect fun getKeyboardState(): State<KeyboardState>
|
||||||
expect fun hideKeyboard(view: Any?)
|
expect fun hideKeyboard(view: Any?)
|
||||||
|
|
||||||
|
expect fun androidIsFinishingMainActivity(): Boolean
|
||||||
|
@ -17,3 +17,5 @@ actual fun LocalMultiplatformView(): Any? = null
|
|||||||
@Composable
|
@Composable
|
||||||
actual fun getKeyboardState(): State<KeyboardState> = remember { mutableStateOf(KeyboardState.Opened) }
|
actual fun getKeyboardState(): State<KeyboardState> = remember { mutableStateOf(KeyboardState.Opened) }
|
||||||
actual fun hideKeyboard(view: Any?) {}
|
actual fun hideKeyboard(view: Any?) {}
|
||||||
|
|
||||||
|
actual fun androidIsFinishingMainActivity(): Boolean = false
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
{-# LANGUAGE LambdaCase #-}
|
{-# LANGUAGE LambdaCase #-}
|
||||||
{-# LANGUAGE NamedFieldPuns #-}
|
{-# LANGUAGE NamedFieldPuns #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE TypeApplications #-}
|
||||||
|
|
||||||
module Simplex.Chat.Mobile where
|
module Simplex.Chat.Mobile where
|
||||||
|
|
||||||
import Control.Concurrent.STM
|
import Control.Concurrent.STM
|
||||||
import Control.Exception (catch)
|
import Control.Exception (catch, SomeException)
|
||||||
import Control.Monad.Except
|
import Control.Monad.Except
|
||||||
import Control.Monad.Reader
|
import Control.Monad.Reader
|
||||||
import Data.Aeson (ToJSON (..))
|
import Data.Aeson (ToJSON (..))
|
||||||
@ -40,8 +41,9 @@ import Simplex.Chat.Options
|
|||||||
import Simplex.Chat.Store
|
import Simplex.Chat.Store
|
||||||
import Simplex.Chat.Store.Profiles
|
import Simplex.Chat.Store.Profiles
|
||||||
import Simplex.Chat.Types
|
import Simplex.Chat.Types
|
||||||
|
import Simplex.Messaging.Agent.Client (agentClientStore)
|
||||||
import Simplex.Messaging.Agent.Env.SQLite (createAgentStore)
|
import Simplex.Messaging.Agent.Env.SQLite (createAgentStore)
|
||||||
import Simplex.Messaging.Agent.Store.SQLite (MigrationConfirmation (..), MigrationError)
|
import Simplex.Messaging.Agent.Store.SQLite (MigrationConfirmation (..), MigrationError, closeSQLiteStore)
|
||||||
import Simplex.Messaging.Client (defaultNetworkConfig)
|
import Simplex.Messaging.Client (defaultNetworkConfig)
|
||||||
import qualified Simplex.Messaging.Crypto as C
|
import qualified Simplex.Messaging.Crypto as C
|
||||||
import Simplex.Messaging.Encoding.String
|
import Simplex.Messaging.Encoding.String
|
||||||
@ -53,6 +55,8 @@ import System.Timeout (timeout)
|
|||||||
|
|
||||||
foreign export ccall "chat_migrate_init" cChatMigrateInit :: CString -> CString -> CString -> Ptr (StablePtr ChatController) -> IO CJSONString
|
foreign export ccall "chat_migrate_init" cChatMigrateInit :: CString -> CString -> CString -> Ptr (StablePtr ChatController) -> IO CJSONString
|
||||||
|
|
||||||
|
foreign export ccall "chat_close_store" cChatCloseStore :: StablePtr ChatController -> IO CString
|
||||||
|
|
||||||
foreign export ccall "chat_send_cmd" cChatSendCmd :: StablePtr ChatController -> CString -> IO CJSONString
|
foreign export ccall "chat_send_cmd" cChatSendCmd :: StablePtr ChatController -> CString -> IO CJSONString
|
||||||
|
|
||||||
foreign export ccall "chat_recv_msg" cChatRecvMsg :: StablePtr ChatController -> IO CJSONString
|
foreign export ccall "chat_recv_msg" cChatRecvMsg :: StablePtr ChatController -> IO CJSONString
|
||||||
@ -95,6 +99,9 @@ cChatMigrateInit fp key conf ctrl = do
|
|||||||
Left e -> pure e
|
Left e -> pure e
|
||||||
newCStringFromLazyBS $ J.encode r
|
newCStringFromLazyBS $ J.encode r
|
||||||
|
|
||||||
|
cChatCloseStore :: StablePtr ChatController -> IO CString
|
||||||
|
cChatCloseStore cPtr = deRefStablePtr cPtr >>= chatCloseStore >>= newCAString
|
||||||
|
|
||||||
-- | send command to chat (same syntax as in terminal for now)
|
-- | send command to chat (same syntax as in terminal for now)
|
||||||
cChatSendCmd :: StablePtr ChatController -> CString -> IO CJSONString
|
cChatSendCmd :: StablePtr ChatController -> CString -> IO CJSONString
|
||||||
cChatSendCmd cPtr cCmd = do
|
cChatSendCmd cPtr cCmd = do
|
||||||
@ -195,6 +202,14 @@ chatMigrateInit dbFilePrefix dbKey confirm = runExceptT $ do
|
|||||||
_ -> dbError e
|
_ -> dbError e
|
||||||
dbError e = Left . DBMErrorSQL dbFile $ show e
|
dbError e = Left . DBMErrorSQL dbFile $ show e
|
||||||
|
|
||||||
|
chatCloseStore :: ChatController -> IO String
|
||||||
|
chatCloseStore ChatController {chatStore, smpAgent} = handleErr $ do
|
||||||
|
closeSQLiteStore chatStore
|
||||||
|
closeSQLiteStore $ agentClientStore smpAgent
|
||||||
|
|
||||||
|
handleErr :: IO () -> IO String
|
||||||
|
handleErr a = (a $> "") `catch` (pure . show @SomeException)
|
||||||
|
|
||||||
chatSendCmd :: ChatController -> ByteString -> IO JSONByteString
|
chatSendCmd :: ChatController -> ByteString -> IO JSONByteString
|
||||||
chatSendCmd cc s = J.encode . APIResponse Nothing <$> runReaderT (execChatCommand s) cc
|
chatSendCmd cc s = J.encode . APIResponse Nothing <$> runReaderT (execChatCommand s) cc
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user