@@ -72,9 +72,12 @@ import heron.scaffold.generated.resources.messages
7272import heron.scaffold.generated.resources.notifications
7373import heron.scaffold.generated.resources.search
7474import heron.scaffold.generated.resources.splash
75+ import kotlin.time.Duration.Companion.seconds
76+ import kotlin.time.TimeSource
7577import kotlin.uuid.ExperimentalUuidApi
7678import kotlin.uuid.Uuid
7779import kotlinx.coroutines.CoroutineScope
80+ import kotlinx.coroutines.delay
7881import kotlinx.coroutines.flow.Flow
7982import kotlinx.coroutines.flow.SharingStarted
8083import kotlinx.coroutines.flow.StateFlow
@@ -85,6 +88,7 @@ import kotlinx.coroutines.flow.filter
8588import kotlinx.coroutines.flow.first
8689import kotlinx.coroutines.flow.flatMapLatest
8790import kotlinx.coroutines.flow.flow
91+ import kotlinx.coroutines.flow.merge
8892import kotlinx.coroutines.flow.onEach
8993import kotlinx.coroutines.launch
9094import org.jetbrains.compose.resources.StringResource
@@ -439,14 +443,10 @@ class PersistedNavigationStateHolder(
439443 ActionStateMutator <NavigationMutation , StateFlow <MultiStackNav >> by appMainScope.actionStateFlowMutator(
440444 initialState = InitialNavigationState ,
441445 started = SharingStarted .Eagerly ,
442- inputs = listOf (
443- forceSignOutMutations(
444- authRepository = authRepository,
445- userDataRepository = userDataRepository,
446- ),
447- ),
448446 actionTransform = { navActions ->
449447 flow {
448+ val startTime = TimeSource .Monotonic .markNow()
449+
450450 // Restore saved nav from disk first
451451 val savedNavigation = userDataRepository.navigation
452452 // Wait for a non empty saved state to be read
@@ -466,17 +466,26 @@ class PersistedNavigationStateHolder(
466466 }
467467 }
468468
469+ val elapsed = startTime.elapsedNow()
470+ if (elapsed < SplashDelay ) delay(SplashDelay - elapsed)
471+
469472 emit { multiStackNav }
470473
471474 emitAll(
472- navActions.mapToMutation { navMutation ->
473- navMutation(
474- ImmutableNavigationContext (
475- state = this ,
476- routeParser = routeParser,
477- ),
478- )
479- },
475+ merge(
476+ navActions.mapToMutation { navMutation ->
477+ navMutation(
478+ ImmutableNavigationContext (
479+ state = this ,
480+ routeParser = routeParser,
481+ ),
482+ )
483+ },
484+ forceSignOutMutations(
485+ authRepository = authRepository,
486+ userDataRepository = userDataRepository,
487+ ),
488+ ),
480489 )
481490 }
482491 },
@@ -661,5 +670,7 @@ private fun AppStack.toStackNav() = StackNav(
661670 children = listOf (rootRoute),
662671)
663672
673+ private val SplashDelay = 1 .seconds
674+
664675private const val ReferringRouteQueryParam = " referringRoute"
665676private const val OAuthUrlPathSegment = " oauth"
0 commit comments