fix mpv crash versions

This commit is contained in:
AbdallahMehiz 2024-04-08 06:16:43 +01:00
parent eb5e983971
commit dd615e7da3
No known key found for this signature in database
GPG key ID: 975266399F5BAF34
4 changed files with 69 additions and 73 deletions

View file

@ -51,6 +51,7 @@ object HistoriesTab : Tab() {
@Composable @Composable
override fun Content() { override fun Content() {
throw RuntimeException()
val context = LocalContext.current val context = LocalContext.current
val fromMore = currentNavigationStyle() == NavStyle.MOVE_HISTORY_TO_MORE val fromMore = currentNavigationStyle() == NavStyle.MOVE_HISTORY_TO_MORE
// Hoisted for history tab's search bar // Hoisted for history tab's search bar

View file

@ -98,8 +98,6 @@ import eu.kanade.tachiyomi.util.system.isNavigationBarNeedsScrim
import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.setComposeContent import eu.kanade.tachiyomi.util.view.setComposeContent
import `is`.xyz.mpv.MPVLib
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
@ -108,7 +106,6 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import logcat.LogPriority import logcat.LogPriority
import tachiyomi.core.i18n.stringResource import tachiyomi.core.i18n.stringResource
import tachiyomi.core.util.lang.launchIO import tachiyomi.core.util.lang.launchIO
@ -139,7 +136,6 @@ class MainActivity : BaseActivity() {
var ready = false var ready = false
private var navigator: Navigator? = null private var navigator: Navigator? = null
private val recordMPVVersion = RecordMPVVersion(this)
init { init {
registerSecureActivity(this) registerSecureActivity(this)
@ -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()
}
}
} }
} }

View file

@ -5,7 +5,6 @@ import android.os.Build
import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.WebViewUtil import eu.kanade.tachiyomi.util.system.WebViewUtil
import eu.kanade.tachiyomi.util.system.createFileInCacheDir import eu.kanade.tachiyomi.util.system.createFileInCacheDir
@ -22,6 +21,8 @@ class CrashLogUtil(
private val animeExtensionManager: AnimeExtensionManager = Injekt.get(), private val animeExtensionManager: AnimeExtensionManager = Injekt.get(),
) { ) {
private val mpvVersions = MpvVersionsUtil(context).mpvVersions
suspend fun dumpLogs() = withNonCancellableContext { suspend fun dumpLogs() = withNonCancellableContext {
try { try {
val file = context.createFileInCacheDir("aniyomi_crash_logs.txt") val file = context.createFileInCacheDir("aniyomi_crash_logs.txt")
@ -49,9 +50,9 @@ class CrashLogUtil(
Device name: ${Build.DEVICE} (${Build.PRODUCT}) Device name: ${Build.DEVICE} (${Build.PRODUCT})
Device model: ${Build.MODEL} Device model: ${Build.MODEL}
WebView: ${WebViewUtil.getVersion(context)} WebView: ${WebViewUtil.getVersion(context)}
MPVLib version: ${MainActivity.mpvVersions.mpvCommit} (${MainActivity.mpvVersions.buildDate}) MPVLib version: ${mpvVersions.mpvCommit} (${mpvVersions.buildDate})
Libplacebo version: ${MainActivity.mpvVersions.libPlacebo} Libplacebo version: ${mpvVersions.libPlacebo}
FFmpeg version: ${MainActivity.mpvVersions.ffmpeg} FFmpeg version: ${mpvVersions.ffmpeg}
""".trimIndent() """.trimIndent()
} }

View file

@ -0,0 +1,63 @@
package eu.kanade.tachiyomi.util
import android.content.Context
import `is`.xyz.mpv.MPVLib
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
class MpvVersionsUtil(context: Context) : MPVLib.LogObserver {
val mpvVersions = MPVVersions()
private var recordMPVLog = true
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
runBlocking { onLoggingComplete() }
}
}
}
}
}
}
private suspend fun onLoggingComplete() {
withContext(Dispatchers.IO) {
mpvVersions.trim()
MPVLib.removeLogObserver(this@MpvVersionsUtil)
MPVLib.destroy()
}
}
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()
}
}
}