@@ -55,11 +55,14 @@ import com.geode.launcher.preferences.ApplicationLogsActivity
5555import com.geode.launcher.BuildConfig
5656import com.geode.launcher.R
5757import com.geode.launcher.UserDirectoryProvider
58+ import com.geode.launcher.preferences.GeodeLogsListingActivity
59+ import com.geode.launcher.preferences.TextViewActivity
5860import com.geode.launcher.ui.theme.Typography
5961import com.geode.launcher.utils.GamePackageUtils
6062import com.geode.launcher.utils.LaunchUtils
6163import com.geode.launcher.utils.PreferenceUtils
6264import kotlinx.coroutines.launch
65+ import java.io.File
6366
6467data 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+
166196fun 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
0 commit comments