Skip to content

Commit

Permalink
fix(main): Fix possible crash (#1463)
Browse files Browse the repository at this point in the history
Co-authored-by: jmir1 <[email protected]>
  • Loading branch information
LuftVerbot and jmir1 authored Mar 7, 2024
1 parent 13397a0 commit e937d8b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import logcat.LogPriority
import tachiyomi.core.i18n.stringResource
import tachiyomi.core.util.lang.launchIO
Expand Down Expand Up @@ -613,14 +614,16 @@ class MainActivity : BaseActivity() {
}

fun onLoggingComplete() {
lifecycleScope.launch(Dispatchers.IO) {
mpvVersions.trim()
MPVLib.removeLogObserver(recordMPVVersion)
MPVLib.destroy()
lifecycleScope.launch {
withContext(Dispatchers.IO) {
mpvVersions.trim()
MPVLib.removeLogObserver(recordMPVVersion)
MPVLib.destroy()
}
}
}

inner class RecordMPVVersion(context: Context) : MPVLib.LogObserver {
inner class RecordMPVVersion(private val context: Context) : MPVLib.LogObserver {
init {
MPVLib.create(context, "v")
MPVLib.addLogObserver(this)
Expand All @@ -640,13 +643,21 @@ class MainActivity : BaseActivity() {
contains("FFmpeg version:") -> mpvVersions.ffmpeg = this
else -> {
recordMPVLog = false
this@MainActivity.onLoggingComplete() // Direct call to MainActivity's method
// Use a safe way to call back to the MainActivity
safeOnLoggingComplete()
}
}
}
}
}
}

private fun safeOnLoggingComplete() {
// Ensure we're calling MainActivity's method safely
(context as? MainActivity)?.runOnUiThread {
context.onLoggingComplete()
}
}
}
}

Expand Down

0 comments on commit e937d8b

Please sign in to comment.