Skip to content

Commit

Permalink
fix(main): Infinite loop on start screen (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuftVerbot authored Feb 18, 2024
1 parent 024abb7 commit 3def939
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.setComposeContent
import `is`.xyz.mpv.MPVLib
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.collectLatest
Expand Down Expand Up @@ -141,10 +142,6 @@ class MainActivity : BaseActivity() {

init {
registerSecureActivity(this)
while (recordMPVLog) { /* Empty loop */ }
mpvVersions.trim()
MPVLib.removeLogObserver(recordMPVVersion)
MPVLib.destroy()
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -613,26 +610,37 @@ class MainActivity : BaseActivity() {
internal val mpvVersions = MPVVersions()

private var recordMPVLog = true
}

class RecordMPVVersion(context: Context) : MPVLib.LogObserver {
init {
MPVLib.create(context, "v")
MPVLib.addLogObserver(this@RecordMPVVersion)
MPVLib.init()
}
fun onLoggingComplete() {
lifecycleScope.launch(Dispatchers.IO) {
mpvVersions.trim()
MPVLib.removeLogObserver(recordMPVVersion)
MPVLib.destroy()
}
}

inner class RecordMPVVersion(context: Context) : MPVLib.LogObserver {
init {
MPVLib.create(context, "v")
MPVLib.addLogObserver(this)
MPVLib.init()
}

override fun logMessage(prefix: String, level: Int, text: String) {
if (prefix != "cplayer") return

if (level == MPVLib.mpvLogLevel.MPV_LOG_LEVEL_V) {
with(text) {
if (recordMPVLog) {
when {
contains("Copyright ©") -> mpvVersions.mpvCommit = this
contains("built on") -> mpvVersions.buildDate = this
contains("libplacebo version:") -> mpvVersions.libPlacebo = this
contains("FFmpeg version:") -> mpvVersions.ffmpeg = this
else -> recordMPVLog = false
override fun logMessage(prefix: String, level: Int, text: String) {
if (prefix != "cplayer") return

if (level == MPVLib.mpvLogLevel.MPV_LOG_LEVEL_V) {
with(text) {
if (recordMPVLog) {
when {
contains("Copyright ©") -> mpvVersions.mpvCommit = this
contains("built on") -> mpvVersions.buildDate = this
contains("libplacebo version:") -> mpvVersions.libPlacebo = this
contains("FFmpeg version:") -> mpvVersions.ffmpeg = this
else -> {
recordMPVLog = false
this@MainActivity.onLoggingComplete() // Direct call to MainActivity's method
}
}
}
Expand Down

0 comments on commit 3def939

Please sign in to comment.