mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8411e28f0d |
+2
-3
@@ -4,8 +4,7 @@ import SectionItemView
|
|||||||
import SectionTextFooter
|
import SectionTextFooter
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material.*
|
import androidx.compose.material.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.MutableState
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
@@ -51,7 +50,7 @@ actual fun SavePassphraseSetting(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
actual fun DatabaseEncryptionFooter(
|
actual fun DatabaseEncryptionFooter(
|
||||||
useKeychain: MutableState<Boolean>,
|
useKeychain: State<Boolean>,
|
||||||
chatDbEncrypted: Boolean?,
|
chatDbEncrypted: Boolean?,
|
||||||
storedKey: MutableState<Boolean>,
|
storedKey: MutableState<Boolean>,
|
||||||
initialRandomDBPassphrase: MutableState<Boolean>,
|
initialRandomDBPassphrase: MutableState<Boolean>,
|
||||||
|
|||||||
+21
-17
@@ -1,9 +1,7 @@
|
|||||||
package chat.simplex.common.views.database
|
package chat.simplex.common.views.database
|
||||||
|
|
||||||
import SectionBottomSpacer
|
import SectionBottomSpacer
|
||||||
import SectionItemView
|
|
||||||
import SectionItemViewSpaceBetween
|
import SectionItemViewSpaceBetween
|
||||||
import SectionTextFooter
|
|
||||||
import SectionView
|
import SectionView
|
||||||
import androidx.compose.foundation.*
|
import androidx.compose.foundation.*
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
@@ -24,13 +22,11 @@ import androidx.compose.ui.text.*
|
|||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.input.*
|
import androidx.compose.ui.text.input.*
|
||||||
import androidx.compose.desktop.ui.tooling.preview.Preview
|
import androidx.compose.desktop.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
|
||||||
import androidx.compose.ui.unit.*
|
import androidx.compose.ui.unit.*
|
||||||
import chat.simplex.common.model.*
|
import chat.simplex.common.model.*
|
||||||
|
import chat.simplex.common.platform.appPlatform
|
||||||
import chat.simplex.common.ui.theme.*
|
import chat.simplex.common.ui.theme.*
|
||||||
import chat.simplex.common.views.helpers.*
|
import chat.simplex.common.views.helpers.*
|
||||||
import chat.simplex.common.model.*
|
|
||||||
import chat.simplex.common.platform.appPlatform
|
|
||||||
import chat.simplex.res.MR
|
import chat.simplex.res.MR
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.datetime.Clock
|
import kotlinx.datetime.Clock
|
||||||
@@ -40,7 +36,7 @@ import kotlin.math.log2
|
|||||||
fun DatabaseEncryptionView(m: ChatModel) {
|
fun DatabaseEncryptionView(m: ChatModel) {
|
||||||
val progressIndicator = remember { mutableStateOf(false) }
|
val progressIndicator = remember { mutableStateOf(false) }
|
||||||
val prefs = m.controller.appPrefs
|
val prefs = m.controller.appPrefs
|
||||||
val useKeychain = remember { mutableStateOf(prefs.storeDBPassphrase.get()) }
|
val useKeychain = remember { prefs.storeDBPassphrase.state }
|
||||||
val initialRandomDBPassphrase = remember { mutableStateOf(prefs.initialRandomDBPassphrase.get()) }
|
val initialRandomDBPassphrase = remember { mutableStateOf(prefs.initialRandomDBPassphrase.get()) }
|
||||||
val storedKey = remember { val key = DatabaseUtils.ksDatabasePassword.get(); mutableStateOf(key != null && key != "") }
|
val storedKey = remember { val key = DatabaseUtils.ksDatabasePassword.get(); mutableStateOf(key != null && key != "") }
|
||||||
// Do not do rememberSaveable on current key to prevent saving it on disk in clear text
|
// Do not do rememberSaveable on current key to prevent saving it on disk in clear text
|
||||||
@@ -63,7 +59,15 @@ fun DatabaseEncryptionView(m: ChatModel) {
|
|||||||
progressIndicator,
|
progressIndicator,
|
||||||
onConfirmEncrypt = {
|
onConfirmEncrypt = {
|
||||||
withApi {
|
withApi {
|
||||||
encryptDatabase(currentKey, newKey, confirmNewKey, initialRandomDBPassphrase, useKeychain, storedKey, progressIndicator)
|
val disableStoring = appPlatform.isDesktop && initialRandomDBPassphrase.value
|
||||||
|
if (disableStoring) {
|
||||||
|
prefs.storeDBPassphrase.set(false)
|
||||||
|
}
|
||||||
|
val success = encryptDatabase(currentKey, newKey, confirmNewKey, initialRandomDBPassphrase, useKeychain, storedKey, progressIndicator)
|
||||||
|
if (!success && disableStoring) {
|
||||||
|
// Rollback in case of it is finished with error in order to allow to repeat the process again
|
||||||
|
prefs.storeDBPassphrase.set(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -86,7 +90,7 @@ fun DatabaseEncryptionView(m: ChatModel) {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DatabaseEncryptionLayout(
|
fun DatabaseEncryptionLayout(
|
||||||
useKeychain: MutableState<Boolean>,
|
useKeychain: State<Boolean>,
|
||||||
prefs: AppPreferences,
|
prefs: AppPreferences,
|
||||||
chatDbEncrypted: Boolean?,
|
chatDbEncrypted: Boolean?,
|
||||||
currentKey: MutableState<String>,
|
currentKey: MutableState<String>,
|
||||||
@@ -104,15 +108,15 @@ fun DatabaseEncryptionLayout(
|
|||||||
SectionView(null) {
|
SectionView(null) {
|
||||||
SavePassphraseSetting(useKeychain.value, initialRandomDBPassphrase.value, storedKey.value, progressIndicator.value) { checked ->
|
SavePassphraseSetting(useKeychain.value, initialRandomDBPassphrase.value, storedKey.value, progressIndicator.value) { checked ->
|
||||||
if (checked) {
|
if (checked) {
|
||||||
setUseKeychain(true, useKeychain, prefs)
|
setUseKeychain(true, prefs)
|
||||||
} else if (storedKey.value) {
|
} else if (storedKey.value) {
|
||||||
removePassphraseAlert {
|
removePassphraseAlert {
|
||||||
DatabaseUtils.ksDatabasePassword.remove()
|
DatabaseUtils.ksDatabasePassword.remove()
|
||||||
setUseKeychain(false, useKeychain, prefs)
|
setUseKeychain(false, prefs)
|
||||||
storedKey.value = false
|
storedKey.value = false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setUseKeychain(false, useKeychain, prefs)
|
setUseKeychain(false, prefs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,15 +139,16 @@ fun DatabaseEncryptionLayout(
|
|||||||
keyboardActions = KeyboardActions(onNext = { defaultKeyboardAction(ImeAction.Next) }),
|
keyboardActions = KeyboardActions(onNext = { defaultKeyboardAction(ImeAction.Next) }),
|
||||||
)
|
)
|
||||||
val onClickUpdate = {
|
val onClickUpdate = {
|
||||||
|
val disableStoring = appPlatform.isDesktop && initialRandomDBPassphrase.value
|
||||||
// Don't do things concurrently. Shouldn't be here concurrently, just in case
|
// Don't do things concurrently. Shouldn't be here concurrently, just in case
|
||||||
if (!progressIndicator.value) {
|
if (!progressIndicator.value) {
|
||||||
if (currentKey.value == "") {
|
if (currentKey.value == "") {
|
||||||
if (useKeychain.value)
|
if (useKeychain.value && !disableStoring)
|
||||||
encryptDatabaseSavedAlert(onConfirmEncrypt)
|
encryptDatabaseSavedAlert(onConfirmEncrypt)
|
||||||
else
|
else
|
||||||
encryptDatabaseAlert(onConfirmEncrypt)
|
encryptDatabaseAlert(onConfirmEncrypt)
|
||||||
} else {
|
} else {
|
||||||
if (useKeychain.value)
|
if (useKeychain.value && !disableStoring)
|
||||||
changeDatabaseKeySavedAlert(onConfirmEncrypt)
|
changeDatabaseKeySavedAlert(onConfirmEncrypt)
|
||||||
else
|
else
|
||||||
changeDatabaseKeyAlert(onConfirmEncrypt)
|
changeDatabaseKeyAlert(onConfirmEncrypt)
|
||||||
@@ -218,7 +223,7 @@ expect fun SavePassphraseSetting(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
expect fun DatabaseEncryptionFooter(
|
expect fun DatabaseEncryptionFooter(
|
||||||
useKeychain: MutableState<Boolean>,
|
useKeychain: State<Boolean>,
|
||||||
chatDbEncrypted: Boolean?,
|
chatDbEncrypted: Boolean?,
|
||||||
storedKey: MutableState<Boolean>,
|
storedKey: MutableState<Boolean>,
|
||||||
initialRandomDBPassphrase: MutableState<Boolean>,
|
initialRandomDBPassphrase: MutableState<Boolean>,
|
||||||
@@ -242,8 +247,7 @@ fun resetFormAfterEncryption(
|
|||||||
storedKey.value = stored
|
storedKey.value = stored
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setUseKeychain(value: Boolean, useKeychain: MutableState<Boolean>, prefs: AppPreferences) {
|
fun setUseKeychain(value: Boolean, prefs: AppPreferences) {
|
||||||
useKeychain.value = value
|
|
||||||
prefs.storeDBPassphrase.set(value)
|
prefs.storeDBPassphrase.set(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,7 +365,7 @@ suspend fun encryptDatabase(
|
|||||||
newKey: MutableState<String>,
|
newKey: MutableState<String>,
|
||||||
confirmNewKey: MutableState<String>,
|
confirmNewKey: MutableState<String>,
|
||||||
initialRandomDBPassphrase: MutableState<Boolean>,
|
initialRandomDBPassphrase: MutableState<Boolean>,
|
||||||
useKeychain: MutableState<Boolean>,
|
useKeychain: State<Boolean>,
|
||||||
storedKey: MutableState<Boolean>,
|
storedKey: MutableState<Boolean>,
|
||||||
progressIndicator: MutableState<Boolean>
|
progressIndicator: MutableState<Boolean>
|
||||||
): Boolean {
|
): Boolean {
|
||||||
|
|||||||
+2
-3
@@ -4,8 +4,7 @@ import SectionItemView
|
|||||||
import SectionTextFooter
|
import SectionTextFooter
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material.*
|
import androidx.compose.material.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.MutableState
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
@@ -51,7 +50,7 @@ actual fun SavePassphraseSetting(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
actual fun DatabaseEncryptionFooter(
|
actual fun DatabaseEncryptionFooter(
|
||||||
useKeychain: MutableState<Boolean>,
|
useKeychain: State<Boolean>,
|
||||||
chatDbEncrypted: Boolean?,
|
chatDbEncrypted: Boolean?,
|
||||||
storedKey: MutableState<Boolean>,
|
storedKey: MutableState<Boolean>,
|
||||||
initialRandomDBPassphrase: MutableState<Boolean>,
|
initialRandomDBPassphrase: MutableState<Boolean>,
|
||||||
|
|||||||
Reference in New Issue
Block a user