key storage implementation
This commit is contained in:
@@ -85,7 +85,6 @@ import com.vitorpamplona.amethyst.desktop.ui.FeedScreen
|
||||
import com.vitorpamplona.amethyst.desktop.ui.LoginScreen
|
||||
import com.vitorpamplona.amethyst.desktop.ui.NotificationsScreen
|
||||
import com.vitorpamplona.amethyst.desktop.ui.UserProfileScreen
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.SecureKeyStorage
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
@@ -213,14 +212,14 @@ fun App(
|
||||
) {
|
||||
var currentScreen by remember { mutableStateOf<DesktopScreen>(DesktopScreen.Feed) }
|
||||
val relayManager = remember { DesktopRelayConnectionManager() }
|
||||
val secureStorage = remember { SecureKeyStorage() }
|
||||
val accountManager = remember { AccountManager(secureStorage) }
|
||||
val accountManager = remember { AccountManager.create() }
|
||||
val accountState by accountManager.accountState.collectAsState()
|
||||
val scope = remember { CoroutineScope(SupervisorJob() + Dispatchers.Main) }
|
||||
|
||||
// Try to load saved account on startup
|
||||
DisposableEffect(Unit) {
|
||||
scope.launch {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
// Load account on IO dispatcher to avoid blocking UI with password prompt (readLine)
|
||||
accountManager.loadSavedAccount()
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.vitorpamplona.amethyst.commons.account.AccountManager
|
||||
import com.vitorpamplona.amethyst.commons.account.AccountState
|
||||
import com.vitorpamplona.amethyst.commons.ui.auth.LoginCard
|
||||
import com.vitorpamplona.amethyst.commons.ui.auth.NewKeyWarningCard
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
@@ -76,8 +77,8 @@ fun LoginScreen(
|
||||
LoginCard(
|
||||
onLogin = { keyInput ->
|
||||
accountManager.loginWithKey(keyInput).map {
|
||||
// Save account to secure storage
|
||||
scope.launch {
|
||||
// Save account to secure storage (use IO dispatcher to avoid blocking UI)
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountManager.saveCurrentAccount()
|
||||
onLoginSuccess()
|
||||
}
|
||||
@@ -96,8 +97,8 @@ fun LoginScreen(
|
||||
nsec = generatedAccount!!.nsec,
|
||||
onContinue = {
|
||||
showNewKeyDialog = false
|
||||
// Save generated account
|
||||
scope.launch {
|
||||
// Save generated account (use IO dispatcher to avoid blocking UI)
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountManager.saveCurrentAccount()
|
||||
onLoginSuccess()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user