Skip to content

Commit 7b2a5ca

Browse files
committed
fix: When the Create / Unlock vault screen is moved into background clear the password field
1 parent 0f23706 commit 7b2a5ca

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

common/src/commonMain/kotlin/com/artemchep/keyguard/feature/keyguard/setup/SetupStateProducer.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.artemchep.keyguard.platform.crashlyticsIsEnabled
2626
import com.artemchep.keyguard.platform.crashlyticsSetEnabled
2727
import com.artemchep.keyguard.res.Res
2828
import com.artemchep.keyguard.res.*
29+
import kotlinx.coroutines.awaitCancellation
2930
import kotlinx.coroutines.flow.MutableStateFlow
3031
import kotlinx.coroutines.flow.combine
3132
import kotlinx.coroutines.flow.flowOf
@@ -63,6 +64,17 @@ fun setupScreenState(
6364
val passwordSink = mutablePersistedFlow("password") { DEFAULT_PASSWORD }
6465
val passwordState = mutableComposeState(passwordSink)
6566

67+
// Clear the password field when the screen
68+
// moves into background.
69+
launchUi {
70+
try {
71+
awaitCancellation()
72+
} finally {
73+
passwordState.value = DEFAULT_PASSWORD
74+
passwordSink.value = DEFAULT_PASSWORD
75+
}
76+
}
77+
6678
val createVaultByMasterPasswordFn = createVaultWithMasterPassword
6779
.let {
6880
CreateVaultWithPassword(executor, it)

common/src/commonMain/kotlin/com/artemchep/keyguard/feature/keyguard/unlock/UnlockStateProducer.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import com.artemchep.keyguard.ui.FlatItemAction
4141
import kotlinx.collections.immutable.persistentListOf
4242
import kotlinx.coroutines.Dispatchers
4343
import kotlinx.coroutines.GlobalScope
44+
import kotlinx.coroutines.awaitCancellation
4445
import kotlinx.coroutines.flow.SharingStarted
4546
import kotlinx.coroutines.flow.combine
4647
import kotlinx.coroutines.flow.onStart
@@ -128,6 +129,17 @@ fun unlockScreenState(
128129
val passwordSink = mutablePersistedFlow("password") { DEFAULT_PASSWORD }
129130
val passwordState = mutableComposeState(passwordSink)
130131

132+
// Clear the password field when the screen
133+
// moves into background.
134+
launchUi {
135+
try {
136+
awaitCancellation()
137+
} finally {
138+
passwordState.value = DEFAULT_PASSWORD
139+
passwordSink.value = DEFAULT_PASSWORD
140+
}
141+
}
142+
131143
val actions = persistentListOf(
132144
FlatItemAction(
133145
icon = Icons.Outlined.Delete,

common/src/commonMain/kotlin/com/artemchep/keyguard/feature/navigation/state/RememberStateFlowScope.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ interface RememberStateFlowScope : RememberStateFlowScopeSub, CoroutineScope, Tr
115115
): () -> Unit
116116

117117
fun launchUi(
118-
block: CoroutineScope.() -> Unit,
118+
block: suspend CoroutineScope.() -> Unit,
119119
): () -> Unit
120120

121121
fun action(block: suspend () -> Unit)

common/src/commonMain/kotlin/com/artemchep/keyguard/feature/navigation/state/RememberStateFlowScopeImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class RememberStateFlowScopeImpl(
208208
}
209209
}
210210

211-
override fun launchUi(block: CoroutineScope.() -> Unit): () -> Unit {
211+
override fun launchUi(block: suspend CoroutineScope.() -> Unit): () -> Unit {
212212
val job = isStartedFlow
213213
.mapLatest { active ->
214214
if (!active) {

0 commit comments

Comments
 (0)