Log app crash exceptions in dumped crash logs (#742)

(cherry picked from commit a3d438e2f5b427eb8b4c391ab9fe10c5a83baf29)
This commit is contained in:
FooIbar 2024-05-03 02:59:29 +08:00 committed by Jobobby04
parent 65ed3c5ae6
commit 14dae420f5
2 changed files with 3 additions and 2 deletions

View File

@ -37,7 +37,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

@ -20,12 +20,13 @@ class CrashLogUtil(
private val extensionManager: ExtensionManager = Injekt.get(),
) {
suspend fun dumpLogs() = withNonCancellableContext {
suspend fun dumpLogs(exception: Throwable? = null) = withNonCancellableContext {
try {
val file = context.createFileInCacheDir("tachiyomi_crash_logs.txt")
file.appendText(getDebugInfo() + "\n\n")
getExtensionsInfo()?.let { file.appendText("$it\n\n") }
exception?.let { file.appendText("$it\n\n") }
Runtime.getRuntime().exec("logcat *:E -d -f ${file.absolutePath}").waitFor()