@@ -37,8 +37,10 @@ import com.ichi2.anki.dialogs.DialogHandlerMessage
3737import com.ichi2.anki.dialogs.ImportDialog
3838import com.ichi2.anki.exception.ManuallyReportedException
3939import com.ichi2.anki.onSelectedCsvForImport
40+ import com.ichi2.anki.servicelayer.DebugInfoService
4041import com.ichi2.anki.showImportDialog
4142import com.ichi2.compat.CompatHelper
43+ import kotlinx.coroutines.launch
4244import org.jetbrains.annotations.Contract
4345import timber.log.Timber
4446import 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