Log app crash exceptions in dumped crash logs

Co-authored-by: FooIbar <118464521+FooIbar@users.noreply.github.com>
This commit is contained in:
Secozzi 2024-07-11 21:12:33 +02:00
parent c04e039d36
commit a10fc6dcb7
No known key found for this signature in database
GPG key ID: 71E9C97D8DDC2662
2 changed files with 3 additions and 2 deletions

View file

@ -40,7 +40,7 @@ fun CrashScreen(
acceptText = stringResource(MR.strings.pref_dump_crash_logs),
onAcceptClick = {
scope.launch {
CrashLogUtil(context).dumpLogs()
CrashLogUtil(context).dumpLogs(exception)
}
},
rejectText = stringResource(MR.strings.crash_screen_restart_application),

View file

@ -22,13 +22,14 @@ class CrashLogUtil(
private val animeExtensionManager: AnimeExtensionManager = Injekt.get(),
) {
suspend fun dumpLogs() = withNonCancellableContext {
suspend fun dumpLogs(exception: Throwable? = null) = withNonCancellableContext {
try {
val file = context.createFileInCacheDir("aniyomi_crash_logs.txt")
file.appendText(getDebugInfo() + "\n\n")
getMangaExtensionsInfo()?.let { file.appendText("$it\n\n") }
getAnimeExtensionsInfo()?.let { file.appendText("$it\n\n") }
exception?.let { file.appendText("$it\n\n") }
Runtime.getRuntime().exec("logcat *:E -d -f ${file.absolutePath}").waitFor()