From 4165c22c2bc8b748bc8d4c1908f3d511cc2d1ba2 Mon Sep 17 00:00:00 2001 From: qimiko <25387744+qimiko@users.noreply.github.com> Date: Fri, 16 Feb 2024 17:59:38 -0700 Subject: [PATCH] crash ui tweaks --- .../java/com/geode/launcher/MainActivity.kt | 55 ++++++++++++------- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/geode/launcher/MainActivity.kt b/app/src/main/java/com/geode/launcher/MainActivity.kt index a8552d2b..01f61f1d 100644 --- a/app/src/main/java/com/geode/launcher/MainActivity.kt +++ b/app/src/main/java/com/geode/launcher/MainActivity.kt @@ -619,6 +619,32 @@ fun onSettings(context: Context) { context.startActivity(launchIntent) } +suspend fun showFailureSnackbar( + context: Context, + loadFailureInfo: LoadFailureInfo, + snackbarHostState: SnackbarHostState, + onActionPerformed: () -> Unit +) { + val message = if (loadFailureInfo.title == LaunchUtils.LauncherError.CRASHED) { + context.getString(R.string.launcher_crashed) + } else { + context.getString(R.string.launcher_failed_to_load) + } + + val res = snackbarHostState.showSnackbar( + message = message, + actionLabel = context.getString(R.string.launcher_error_more), + duration = SnackbarDuration.Indefinite, + ) + + when (res) { + SnackbarResult.ActionPerformed -> { + onActionPerformed() + } + SnackbarResult.Dismissed -> {} + } +} + @Composable fun MainScreen( gdInstalled: Boolean = true, @@ -654,27 +680,16 @@ fun MainScreen( val snackbarHostState = remember { SnackbarHostState() } - var showErrorInfo by remember { mutableStateOf(false) } - val hasError = loadFailureInfo != null - LaunchedEffect(hasError) { - if (loadFailureInfo != null) { - val message = if (loadFailureInfo.title == LaunchUtils.LauncherError.CRASHED) { - context.getString(R.string.launcher_crashed) - } else { - context.getString(R.string.launcher_failed_to_load) - } - - val res = snackbarHostState.showSnackbar( - message = message, - actionLabel = context.getString(R.string.launcher_error_more), - duration = SnackbarDuration.Indefinite, - ) + // automatically show load failed dialog (but not crash) + var showErrorInfo by remember { mutableStateOf( + loadFailureInfo != null && loadFailureInfo.title != LaunchUtils.LauncherError.CRASHED + )} - when (res) { - SnackbarResult.ActionPerformed -> { - showErrorInfo = true - } - SnackbarResult.Dismissed -> {} + val hasError = loadFailureInfo != null + LaunchedEffect(hasError, showErrorInfo) { + if (!showErrorInfo && loadFailureInfo != null) { + showFailureSnackbar(context, loadFailureInfo, snackbarHostState) { + showErrorInfo = true } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9d2dfcd7..955af344 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,7 +34,7 @@ Safe mode disables loading of all mods, allowing one to remove problematic mods or diagnose crashes. If you\'re not experiencing issues with Geode, you should probably not be using safe mode. Geode failed to load. Geode crashed. - Learn more + Help Error details View logs Copy