Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Loading