This commit is contained in:
Horis 2024-02-06 17:19:42 +08:00
parent f2edcdbf12
commit fb5f24de60
3 changed files with 13 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import io.legado.app.help.LifecycleHelp
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.permission.PermissionsCompat
import io.legado.app.utils.LogUtils
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -18,6 +19,8 @@ import kotlin.coroutines.CoroutineContext
abstract class BaseService : LifecycleService() { abstract class BaseService : LifecycleService() {
private val simpleName = this::class.simpleName.toString()
fun <T> execute( fun <T> execute(
scope: CoroutineScope = lifecycleScope, scope: CoroutineScope = lifecycleScope,
context: CoroutineContext = Dispatchers.IO, context: CoroutineContext = Dispatchers.IO,
@ -35,12 +38,14 @@ abstract class BaseService : LifecycleService() {
@CallSuper @CallSuper
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
LogUtils.d(simpleName, "onStartCommand $intent")
startForegroundNotification() startForegroundNotification()
return super.onStartCommand(intent, flags, startId) return super.onStartCommand(intent, flags, startId)
} }
@CallSuper @CallSuper
override fun onTaskRemoved(rootIntent: Intent?) { override fun onTaskRemoved(rootIntent: Intent?) {
LogUtils.d(simpleName, "onTaskRemoved")
super.onTaskRemoved(rootIntent) super.onTaskRemoved(rootIntent)
stopSelf() stopSelf()
} }

View File

@ -3,6 +3,7 @@ package io.legado.app.constant
import android.util.Log import android.util.Log
import io.legado.app.BuildConfig import io.legado.app.BuildConfig
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.utils.LogUtils
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import splitties.init.appCtx import splitties.init.appCtx
@ -21,6 +22,11 @@ object AppLog {
if (mLogs.size > 100) { if (mLogs.size > 100) {
mLogs.removeLastOrNull() mLogs.removeLastOrNull()
} }
if (throwable == null) {
LogUtils.d("AppLog", message)
} else {
LogUtils.d("AppLog", "$message\n${throwable.stackTraceToString()}")
}
mLogs.add(0, Triple(System.currentTimeMillis(), message, throwable)) mLogs.add(0, Triple(System.currentTimeMillis(), message, throwable))
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
val stackTrace = Thread.currentThread().stackTrace val stackTrace = Thread.currentThread().stackTrace

View File

@ -13,6 +13,7 @@ import io.legado.app.help.config.AppConfig
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.HttpReadAloudService import io.legado.app.service.HttpReadAloudService
import io.legado.app.service.TTSReadAloudService import io.legado.app.service.TTSReadAloudService
import io.legado.app.utils.LogUtils
import io.legado.app.utils.StringUtils import io.legado.app.utils.StringUtils
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
@ -53,6 +54,7 @@ object ReadAloud {
intent.putExtra("play", play) intent.putExtra("play", play)
intent.putExtra("pageIndex", pageIndex) intent.putExtra("pageIndex", pageIndex)
intent.putExtra("startPos", startPos) intent.putExtra("startPos", startPos)
LogUtils.d("ReadAloud", intent.toString())
try { try {
ContextCompat.startForegroundService(context, intent) ContextCompat.startForegroundService(context, intent)
} catch (e: Exception) { } catch (e: Exception) {