Skip to content

Commit

Permalink
crash ui tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Feb 17, 2024
1 parent c53a23f commit 4165c22
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
55 changes: 35 additions & 20 deletions app/src/main/java/com/geode/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<string name="safe_mode_enable_description">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.</string>
<string name="launcher_failed_to_load">Geode failed to load.</string>
<string name="launcher_crashed">Geode crashed.</string>
<string name="launcher_error_more">Learn more</string>
<string name="launcher_error_more">Help</string>
<string name="launcher_error_details">Error details</string>
<string name="launcher_error_view_logs">View logs</string>
<string name="launcher_error_copy_error_alt">Copy</string>
Expand Down

0 comments on commit 4165c22

Please sign in to comment.