diff --git a/composeApp/src/androidMain/AndroidManifest.xml b/composeApp/src/androidMain/AndroidManifest.xml index d8bf7ea..89f75cb 100644 --- a/composeApp/src/androidMain/AndroidManifest.xml +++ b/composeApp/src/androidMain/AndroidManifest.xml @@ -22,7 +22,6 @@ diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/App.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/App.kt index ff641b0..22bf5d6 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/App.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/App.kt @@ -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 { backStackEntry -> OnboardingScreen( diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt index 3daad42..0f7dffc 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt @@ -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 { diff --git a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt index 058eb3d..1141252 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt @@ -39,8 +39,8 @@ class NostrViewModel( private val nostr: Nostr, private val secretStore: SecretStorage ) : ViewModel() { - private val _emptySecret = MutableStateFlow(null) - val emptySecret = _emptySecret.asStateFlow() + private val _signerRequired = MutableStateFlow(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}") }