Skip to content

Commit 4508abc

Browse files
committed
prompt user to view crash in error dialog
1 parent 38a9944 commit 4508abc

4 files changed

Lines changed: 64 additions & 19 deletions

File tree

app/src/main/java/com/geode/launcher/main/ErrorComponents.kt

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ import com.geode.launcher.preferences.ApplicationLogsActivity
5555
import com.geode.launcher.BuildConfig
5656
import com.geode.launcher.R
5757
import com.geode.launcher.UserDirectoryProvider
58+
import com.geode.launcher.preferences.GeodeLogsListingActivity
59+
import com.geode.launcher.preferences.TextViewActivity
5860
import com.geode.launcher.ui.theme.Typography
5961
import com.geode.launcher.utils.GamePackageUtils
6062
import com.geode.launcher.utils.LaunchUtils
6163
import com.geode.launcher.utils.PreferenceUtils
6264
import kotlinx.coroutines.launch
65+
import java.io.File
6366

6467
data class LoadFailureInfo(
6568
val title: LaunchUtils.LauncherError,
@@ -137,14 +140,28 @@ fun ErrorInfoTitle(failureReason: LaunchUtils.LauncherError) {
137140

138141
}
139142

140-
fun onShareCrash(context: Context) {
143+
fun findSomethingForCrash(context: Context): File? {
141144
val lastCrash = LaunchUtils.getLastCrash(context)
145+
if (lastCrash != null) {
146+
return lastCrash
147+
}
148+
149+
val logsDirectory = LaunchUtils.getGeodeLogsDirectory(context)
150+
if (!logsDirectory.exists()) {
151+
return null
152+
}
153+
154+
return logsDirectory.listFiles()?.maxByOrNull { it.lastModified() }
155+
}
156+
157+
fun onShareCrash(context: Context) {
158+
val lastCrash = findSomethingForCrash(context)
142159
if (lastCrash == null) {
143160
Toast.makeText(context, R.string.launcher_error_export_missing, Toast.LENGTH_SHORT).show()
144161
return
145162
}
146163

147-
val baseDirectory = LaunchUtils.getBaseDirectory(context)
164+
val baseDirectory = LaunchUtils.getBaseDirectory(context, true)
148165

149166
val providerLocation = lastCrash.toRelativeString(baseDirectory)
150167
val documentsPath = "${UserDirectoryProvider.ROOT}${providerLocation}"
@@ -163,6 +180,19 @@ fun onShareCrash(context: Context) {
163180
}
164181
}
165182

183+
fun openLastCrash(context: Context) {
184+
val lastCrash = findSomethingForCrash(context)
185+
if (lastCrash == null) {
186+
Toast.makeText(context, R.string.launcher_error_export_missing, Toast.LENGTH_SHORT).show()
187+
return
188+
}
189+
190+
val launchIntent = Intent(context, TextViewActivity::class.java).run {
191+
putExtra(TextViewActivity.EXTRA_LOG_VIEW_FILENAME, lastCrash.path)
192+
}
193+
context.startActivity(launchIntent)
194+
}
195+
166196
fun onShowLogs(context: Context) {
167197
val launchIntent = Intent(context, ApplicationLogsActivity::class.java)
168198
context.startActivity(launchIntent)
@@ -255,20 +285,34 @@ fun ErrorInfoActions(extraDetails: String?, modifier: Modifier = Modifier) {
255285
Text(stringResource(R.string.launcher_error_copy))
256286
}
257287
} else {
258-
Button(onClick = { onShareCrash(context) }) {
259-
Icon(
260-
painterResource(R.drawable.icon_share),
261-
contentDescription = null
262-
)
263-
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
264-
Text(stringResource(R.string.launcher_error_export_crash))
265-
}
288+
val crashFile = remember { findSomethingForCrash(context) }
289+
val readableCrash = remember { crashFile?.extension == "log" }
266290

267-
val developerSettingsEnabled = remember {
268-
PreferenceUtils.get(context).getBoolean(PreferenceUtils.Key.DEVELOPER_MODE)
269-
}
270-
if (developerSettingsEnabled) {
271-
FilledTonalButton(onClick = { onShowLogs(context) }) {
291+
if (crashFile != null) {
292+
Button(onClick = { onShareCrash(context) }) {
293+
Icon(
294+
painterResource(R.drawable.icon_share),
295+
contentDescription = null
296+
)
297+
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
298+
Text(stringResource(R.string.launcher_error_export_crash))
299+
}
300+
301+
if (readableCrash) {
302+
FilledTonalButton(onClick = { openLastCrash(context) }) {
303+
Icon(
304+
painterResource(R.drawable.icon_description),
305+
contentDescription = null
306+
)
307+
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
308+
Text(stringResource(R.string.launcher_error_view_details))
309+
}
310+
}
311+
} else {
312+
Button(onClick = {
313+
val launchIntent = Intent(context, GeodeLogsListingActivity::class.java)
314+
context.startActivity(launchIntent)
315+
}) {
272316
Icon(
273317
painterResource(R.drawable.icon_description),
274318
contentDescription = null

app/src/main/java/com/geode/launcher/preferences/CrashLogsActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class CrashLogsActivity : ComponentActivity() {
8484
}
8585

8686
fun shareCrash(context: Context, filename: String) {
87-
val baseDirectory = LaunchUtils.getBaseDirectory(context)
87+
val baseDirectory = LaunchUtils.getBaseDirectory(context, true)
8888
val crashPath = File(LaunchUtils.getCrashDirectory(context), filename)
8989

9090
if (!crashPath.exists()) {

app/src/main/java/com/geode/launcher/preferences/GeodeLogsListingActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class GeodeLogsListingActivity : ComponentActivity() {
8080
}
8181

8282
fun shareLog(context: Context, filename: String) {
83-
val baseDirectory = LaunchUtils.getBaseDirectory(context)
83+
val baseDirectory = LaunchUtils.getBaseDirectory(context, true)
8484
val crashPath = File(LaunchUtils.getGeodeLogsDirectory(context), filename)
8585

8686
if (!crashPath.exists()) {

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<string name="launcher_error_view_logs">View logs</string>
5454
<string name="launcher_error_copy_error_alt">Copy</string>
5555
<string name="launcher_error_copy">Copy details</string>
56+
<string name="launcher_error_view_details">View details</string>
5657
<string name="launcher_error_export_crash">Share crash</string>
5758
<string name="launcher_error_export_missing">No crash dump was found!</string>
5859
<string name="launcher_error_device_info">Android %2$s, %1$s (%5$s)\nGD %4$s, Geode %3$s + v%6$s</string>
@@ -118,10 +119,10 @@
118119
<string name="load_failed_crashed_description">A crash was reported during the last session. Try to:</string>
119120
<string name="load_failed_recommendation_reinstall">Reinstall Geometry Dash.</string>
120121
<string name="load_failed_recommendation_switch_32bit_abi">Install the 32-bit version of the launcher.</string>
121-
<string name="load_failed_recommendation_switch_64bit_abi">Install the non 32-bit version of the launcher.</string>
122+
<string name="load_failed_recommendation_switch_64bit_abi">Install the non-32-bit version of the launcher.</string>
122123
<string name="load_failed_recommendation_update">Verify that the latest versions of the launcher and Geometry Dash are installed.</string>
123124
<string name="load_failed_recommendation_report">Report this issue to the developers.</string>
124-
<string name="load_failed_recommendation_safe_mode">Enable the safe mode button in Settings.</string>
125+
<string name="load_failed_recommendation_safe_mode">Use the safe mode button in Settings.</string>
125126
<string name="load_failed_recommendation_dev_stl">Devs: If this is a locally built Geode version, please use the c++_shared ANDROID_STL!</string>
126127

127128
<string name="message_box_cancel">Cancel</string>

0 commit comments

Comments
 (0)