Skip to content

Commit 0818da2

Browse files
committed
improvement(import): 'copy debug info' includes system info
Issue 19616
1 parent b1d177a commit 0818da2

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

AnkiDroid/src/main/java/com/ichi2/utils/ImportUtils.kt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ import com.ichi2.anki.dialogs.DialogHandlerMessage
3737
import com.ichi2.anki.dialogs.ImportDialog
3838
import com.ichi2.anki.exception.ManuallyReportedException
3939
import com.ichi2.anki.onSelectedCsvForImport
40+
import com.ichi2.anki.servicelayer.DebugInfoService
4041
import com.ichi2.anki.showImportDialog
4142
import com.ichi2.compat.CompatHelper
43+
import kotlinx.coroutines.launch
4244
import org.jetbrains.annotations.Contract
4345
import timber.log.Timber
4446
import java.io.File
@@ -323,6 +325,20 @@ object ImportUtils {
323325
failure: ImportResult.Failure,
324326
exitActivity: Boolean,
325327
) {
328+
// Use applicationScope: IntentHandler calls this and does not have a lifecycleScope
329+
fun copyDebugInfo(debugInfo: String) =
330+
AnkiDroidApp.applicationScope.launch {
331+
Timber.i("copying debug info to clipboard")
332+
val stringToCopy =
333+
buildString {
334+
appendLine(debugInfo)
335+
appendLine()
336+
appendLine(DebugInfoService.getDebugInfo(activity))
337+
}
338+
339+
activity.copyToClipboard(stringToCopy)
340+
}
341+
326342
Timber.d("showImportUnsuccessfulDialog() message %s", failure.humanReadableMessage)
327343
val title = failure.title ?: activity.getString(R.string.import_title_error)
328344
val dialog =
@@ -342,8 +358,7 @@ object ImportUtils {
342358
// 'copy' should not close the dialog
343359
failure.toDebugInfo()?.let { debugInfo ->
344360
dialog.negativeButton.setOnClickListener {
345-
Timber.i("copying debug info to clipboard")
346-
activity.copyToClipboard(debugInfo)
361+
copyDebugInfo(debugInfo)
347362
}
348363
}
349364
}
@@ -542,17 +557,6 @@ sealed class ImportResult {
542557
val exception: Exception? = null,
543558
val title: String? = null,
544559
) : ImportResult() {
545-
fun toDebugInfo(): String? {
546-
if (exception == null) return null
547-
return buildString {
548-
appendLine(exception.stackTraceToString())
549-
if (title != null) {
550-
appendLine()
551-
appendLine(title)
552-
}
553-
appendLine()
554-
appendLine(humanReadableMessage)
555-
}
556-
}
560+
fun toDebugInfo(): String? = exception?.stackTraceToString()
557561
}
558562
}

0 commit comments

Comments
 (0)