.
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/Theme.App.Starting">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
@@ -82,11 +82,13 @@ fun App(viewModel: NostrViewModel) {
|
||||
|
||||
// Enabled the dynamic color scheme
|
||||
val colorScheme = when {
|
||||
// Enable the dynamic color scheme for Android 12+
|
||||
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S -> {
|
||||
if (darkMode) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
|
||||
// When dark mode is enabled, use the dark color scheme
|
||||
darkMode -> darkColorScheme()
|
||||
// Fallback to the light color scheme
|
||||
else -> expressiveLightColorScheme()
|
||||
}
|
||||
|
||||
@@ -106,22 +108,27 @@ fun App(viewModel: NostrViewModel) {
|
||||
LocalSnackbarHostState provides snackbarHostState,
|
||||
LocalNavController provides navController,
|
||||
) {
|
||||
val emptySecret by viewModel.emptySecret.collectAsState(initial = null)
|
||||
val signerRequired by viewModel.signerRequired.collectAsState(initial = null)
|
||||
val isRelayListEmpty by viewModel.isRelayListEmpty.collectAsState()
|
||||
val sheetState = rememberModalBottomSheetState()
|
||||
|
||||
LaunchedEffect(emptySecret) {
|
||||
LaunchedEffect(signerRequired) {
|
||||
// Navigate to the home screen if the secret is already set
|
||||
if (emptySecret == false) {
|
||||
if (signerRequired == false) {
|
||||
navController.navigate(Screen.Home) {
|
||||
popUpTo(Screen.Onboarding) { inclusive = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Keep the splash screen visible until the secret check is complete
|
||||
if (signerRequired == null) {
|
||||
return@CompositionLocalProvider
|
||||
}
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = if (emptySecret == false) Screen.Home else Screen.Onboarding
|
||||
startDestination = if (signerRequired!!) Screen.Onboarding else Screen.Home
|
||||
) {
|
||||
composable<Screen.Onboarding> { backStackEntry ->
|
||||
OnboardingScreen(
|
||||
|
||||
@@ -36,8 +36,9 @@ class MainActivity : ComponentActivity() {
|
||||
startService(serviceIntent)
|
||||
}
|
||||
|
||||
// Keep the splash screen visible until the signer check is complete
|
||||
splashScreen.setKeepOnScreenCondition {
|
||||
viewModel.emptySecret.value == null
|
||||
viewModel.signerRequired.value == null
|
||||
}
|
||||
|
||||
setContent {
|
||||
|
||||
@@ -39,8 +39,8 @@ class NostrViewModel(
|
||||
private val nostr: Nostr,
|
||||
private val secretStore: SecretStorage
|
||||
) : ViewModel() {
|
||||
private val _emptySecret = MutableStateFlow<Boolean?>(null)
|
||||
val emptySecret = _emptySecret.asStateFlow()
|
||||
private val _signerRequired = MutableStateFlow<Boolean?>(null)
|
||||
val signerRequired = _signerRequired.asStateFlow()
|
||||
|
||||
private val _isCreating = MutableStateFlow(false)
|
||||
val isCreating = _isCreating.asStateFlow()
|
||||
@@ -206,12 +206,12 @@ class NostrViewModel(
|
||||
|
||||
// If no secret is found, show onboarding screen
|
||||
if (secret == null) {
|
||||
_emptySecret.value = true
|
||||
_signerRequired.value = true
|
||||
return@launch
|
||||
}
|
||||
|
||||
// Update the empty secret state
|
||||
_emptySecret.value = false
|
||||
_signerRequired.value = false
|
||||
|
||||
// Handle different signer types
|
||||
if (secret.startsWith("nsec1")) {
|
||||
@@ -294,7 +294,7 @@ class NostrViewModel(
|
||||
viewModelScope.launch {
|
||||
secretStore.clear("user_signer")
|
||||
nostr.signer.switch(Keys.generate())
|
||||
_emptySecret.value = true
|
||||
_signerRequired.value = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ class NostrViewModel(
|
||||
secretStore.set("user_signer", secret)
|
||||
|
||||
// Set an empty secret state
|
||||
_emptySecret.value = false
|
||||
_signerRequired.value = false
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
}
|
||||
@@ -396,18 +396,16 @@ class NostrViewModel(
|
||||
nostr.setSigner(keys)
|
||||
secretStore.set("user_signer", secret)
|
||||
// Set an empty secret state
|
||||
_emptySecret.value = false
|
||||
_signerRequired.value = false
|
||||
} else if (secret.startsWith("bunker://")) {
|
||||
try {
|
||||
val appKeys = getOrInitAppKeys()
|
||||
val bunker = NostrConnectUri.parse(secret)
|
||||
val timeout = Duration.parse("50s") // 50 seconds timeout
|
||||
val remote =
|
||||
NostrConnect(uri = bunker, appKeys = appKeys, timeout = timeout, null)
|
||||
val remote = NostrConnect(uri = bunker, appKeys, timeout, null)
|
||||
nostr.setSigner(remote)
|
||||
secretStore.set("user_signer", secret)
|
||||
// Set an empty secret state
|
||||
_emptySecret.value = false
|
||||
_signerRequired.value = false
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user