Skip to content

Commit

Permalink
fix: Don't run MPV on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
jmir1 committed Apr 11, 2024
1 parent 9145411 commit 71e0d44
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 73 deletions.
69 changes: 0 additions & 69 deletions app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ import eu.kanade.tachiyomi.util.system.isNavigationBarNeedsScrim
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 All @@ -108,7 +106,6 @@ 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 @@ -139,7 +136,6 @@ class MainActivity : BaseActivity() {
var ready = false

private var navigator: Navigator? = null
private val recordMPVVersion = RecordMPVVersion(this)

init {
registerSecureActivity(this)
Expand Down Expand Up @@ -593,71 +589,6 @@ class MainActivity : BaseActivity() {
)
}
}

data class MPVVersions(
var mpvCommit: String = "",
var buildDate: String = "",
var libPlacebo: String = "",
var ffmpeg: String = "",
) {
fun trim() {
mpvCommit = mpvCommit.substringBefore("Copyright").trim()
buildDate = buildDate.substringAfter("built on ").trim()
libPlacebo = libPlacebo.substringAfter(": ").trim()
ffmpeg = ffmpeg.substringAfter(": ").trim()
}
}

internal val mpvVersions = MPVVersions()

private var recordMPVLog = true
}

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

inner class RecordMPVVersion(private val 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
// 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
7 changes: 4 additions & 3 deletions app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.util.system.WebViewUtil
import eu.kanade.tachiyomi.util.system.createFileInCacheDir
import eu.kanade.tachiyomi.util.system.toShareIntent
import eu.kanade.tachiyomi.util.system.toast
import `is`.xyz.mpv.Utils
import tachiyomi.core.util.lang.withNonCancellableContext
import tachiyomi.core.util.lang.withUIContext
import uy.kohesive.injekt.Injekt
Expand Down Expand Up @@ -49,9 +50,9 @@ class CrashLogUtil(
Device name: ${Build.DEVICE} (${Build.PRODUCT})
Device model: ${Build.MODEL}
WebView: ${WebViewUtil.getVersion(context)}
MPVLib version: ${MainActivity.mpvVersions.mpvCommit} (${MainActivity.mpvVersions.buildDate})
Libplacebo version: ${MainActivity.mpvVersions.libPlacebo}
FFmpeg version: ${MainActivity.mpvVersions.ffmpeg}
MPV version: ${Utils.VERSIONS.mpv}
Libplacebo version: ${Utils.VERSIONS.libPlacebo}
FFmpeg version: ${Utils.VERSIONS.ffmpeg}
""".trimIndent()
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ voyager-transitions = { module = "cafe.adriel.voyager:voyager-transitions", vers

ktlint = "org.jlleitschuh.gradle:ktlint-gradle:12.0.3"

aniyomi-mpv = "com.github.aniyomiorg:aniyomi-mpv-lib:1.13.n"
aniyomi-mpv = "com.github.aniyomiorg:aniyomi-mpv-lib:1.14.n"
ffmpeg-kit = "com.github.jmir1:ffmpeg-kit:1.13"
arthenica-smartexceptions = "com.arthenica:smart-exception-java:0.2.1"

Expand Down

0 comments on commit 71e0d44

Please sign in to comment.