From dd615e7da3790faceac24e37d62dc3bf0e34e3be Mon Sep 17 00:00:00 2001 From: AbdallahMehiz Date: Mon, 8 Apr 2024 06:16:43 +0100 Subject: [PATCH] fix mpv crash versions --- .../tachiyomi/ui/history/HistoriesTab.kt | 1 + .../kanade/tachiyomi/ui/main/MainActivity.kt | 69 ------------------- .../eu/kanade/tachiyomi/util/CrashLogUtil.kt | 9 +-- .../kanade/tachiyomi/util/MpvVersionsUtil.kt | 63 +++++++++++++++++ 4 files changed, 69 insertions(+), 73 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/MpvVersionsUtil.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoriesTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoriesTab.kt index 2e1bf41f1..ea48e4ae1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoriesTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoriesTab.kt @@ -51,6 +51,7 @@ object HistoriesTab : Tab() { @Composable override fun Content() { + throw RuntimeException() val context = LocalContext.current val fromMore = currentNavigationStyle() == NavStyle.MOVE_HISTORY_TO_MORE // Hoisted for history tab's search bar diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 408712e3a..e6529948e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -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 @@ -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 @@ -139,7 +136,6 @@ class MainActivity : BaseActivity() { var ready = false private var navigator: Navigator? = null - private val recordMPVVersion = RecordMPVVersion(this) init { 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() - } - } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt index f6bd5951d..371c5efbc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt @@ -5,7 +5,6 @@ import android.os.Build import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager 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.system.WebViewUtil import eu.kanade.tachiyomi.util.system.createFileInCacheDir @@ -22,6 +21,8 @@ class CrashLogUtil( private val animeExtensionManager: AnimeExtensionManager = Injekt.get(), ) { + private val mpvVersions = MpvVersionsUtil(context).mpvVersions + suspend fun dumpLogs() = withNonCancellableContext { try { val file = context.createFileInCacheDir("aniyomi_crash_logs.txt") @@ -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} + MPVLib version: ${mpvVersions.mpvCommit} (${mpvVersions.buildDate}) + Libplacebo version: ${mpvVersions.libPlacebo} + FFmpeg version: ${mpvVersions.ffmpeg} """.trimIndent() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/MpvVersionsUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/MpvVersionsUtil.kt new file mode 100644 index 000000000..ebe2d05b0 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/MpvVersionsUtil.kt @@ -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() + } + } +}