fix(ui): Determine start destination before composing backstack

Check onboarding state in MainActivity before creating the NavBackStack,
so the correct screen is shown from the first frame. Removes the
redundant async check from OverviewViewModel that caused the dashboard
to briefly flash before redirecting to onboarding on fresh installs.
This commit is contained in:
darken
2026-02-24 16:50:05 +01:00
committed by Matthias Urhahn
parent 8df2d78070
commit 679250f7da
2 changed files with 9 additions and 7 deletions
@@ -18,6 +18,7 @@ import eu.darken.capod.common.navigation.NavigationController
import eu.darken.capod.common.navigation.NavigationEntry
import eu.darken.capod.common.theming.CapodTheme
import eu.darken.capod.common.uix.Activity2
import eu.darken.capod.main.core.GeneralSettings
import javax.inject.Inject
@AndroidEntryPoint
@@ -25,14 +26,21 @@ class MainActivity : Activity2() {
@Inject lateinit var navCtrl: NavigationController
@Inject lateinit var navigationEntries: Set<@JvmSuppressWildcards NavigationEntry>
@Inject lateinit var generalSettings: GeneralSettings
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
enableEdgeToEdge()
val startDestination: NavKey = if (generalSettings.isOnboardingDone.value) {
Nav.Main.Overview
} else {
Nav.Main.Onboarding
}
setContent {
val backStack = rememberNavBackStack(Nav.Main.Overview)
val backStack = rememberNavBackStack(startDestination)
navCtrl.setup(backStack)
CapodTheme {
@@ -49,12 +49,6 @@ class OverviewViewModel @Inject constructor(
private val profilesRepo: DeviceProfilesRepo,
) : ViewModel4(dispatcherProvider) {
init {
if (!generalSettings.isOnboardingDone.value) {
navTo(Nav.Main.Onboarding, popUpTo = Nav.Main.Overview, inclusive = true)
}
}
val requestPermissionEvent = SingleEventFlow<Permission>()
val launchUpgradeFlow = SingleEventFlow<(Activity) -> Unit>()