diff --git a/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/OneConfigInterface.kt b/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/OneConfigInterface.kt index 296790546..21f118acc 100644 --- a/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/OneConfigInterface.kt +++ b/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/OneConfigInterface.kt @@ -39,6 +39,8 @@ import androidx.compose.ui.unit.Density import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner import androidx.navigation.compose.rememberNavController +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.withTimeoutOrNull import org.apache.logging.log4j.LogManager import org.polyfrost.oneconfig.internal.OneConfigConfig import org.polyfrost.oneconfig.internal.ui.hud.screens.HudDragLayer @@ -60,6 +62,8 @@ fun guiCloseAnimationMillis(): Long = private const val MAX_CLOSE_ANIMATION_MS = 160L +private const val GRAPH_WAIT_TIMEOUT_MS = 10_000L + @Composable fun OneConfigInterface( windowWidth: Float, @@ -93,15 +97,21 @@ fun OneConfigInterface( ShellState.animateOpeningPage = !restoring && OneConfigConfig.showOpeningPageAnimation // the NavHost only sets its graph once the Shell is composed so wait for it or navigate() // crashes with "must call setGraph() before getGraph()" - var attempts = 0 - while (attempts++ < 600) { - val ready = try { - LocalNavController.current.graph; true - } catch (_: IllegalStateException) { - false + if (ShellState.animateOpeningPage) { + var attempts = 0 + while (attempts++ < 600) { + val ready = try { + LocalNavController.current.graph; true + } catch (_: IllegalStateException) { + false + } + if (ready) break + withFrameNanos { } + } + } else { + withTimeoutOrNull(GRAPH_WAIT_TIMEOUT_MS) { + LocalNavController.current.currentBackStackEntryFlow.first() } - if (ready) break - withFrameNanos { } } try { LocalNavController.wrapper.navigate(initialRoute, clearSearch = !resuming)