mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
f2edcdbf12
commit
fb5f24de60
@ -10,6 +10,7 @@ import io.legado.app.help.LifecycleHelp
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.lib.permission.Permissions
|
||||
import io.legado.app.lib.permission.PermissionsCompat
|
||||
import io.legado.app.utils.LogUtils
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.CoroutineStart
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -18,6 +19,8 @@ import kotlin.coroutines.CoroutineContext
|
||||
|
||||
abstract class BaseService : LifecycleService() {
|
||||
|
||||
private val simpleName = this::class.simpleName.toString()
|
||||
|
||||
fun <T> execute(
|
||||
scope: CoroutineScope = lifecycleScope,
|
||||
context: CoroutineContext = Dispatchers.IO,
|
||||
@ -35,12 +38,14 @@ abstract class BaseService : LifecycleService() {
|
||||
|
||||
@CallSuper
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
LogUtils.d(simpleName, "onStartCommand $intent")
|
||||
startForegroundNotification()
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
LogUtils.d(simpleName, "onTaskRemoved")
|
||||
super.onTaskRemoved(rootIntent)
|
||||
stopSelf()
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package io.legado.app.constant
|
||||
import android.util.Log
|
||||
import io.legado.app.BuildConfig
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.utils.LogUtils
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import splitties.init.appCtx
|
||||
|
||||
@ -21,6 +22,11 @@ object AppLog {
|
||||
if (mLogs.size > 100) {
|
||||
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))
|
||||
if (BuildConfig.DEBUG) {
|
||||
val stackTrace = Thread.currentThread().stackTrace
|
||||
|
@ -13,6 +13,7 @@ import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.service.BaseReadAloudService
|
||||
import io.legado.app.service.HttpReadAloudService
|
||||
import io.legado.app.service.TTSReadAloudService
|
||||
import io.legado.app.utils.LogUtils
|
||||
import io.legado.app.utils.StringUtils
|
||||
import io.legado.app.utils.postEvent
|
||||
import io.legado.app.utils.toastOnUi
|
||||
@ -53,6 +54,7 @@ object ReadAloud {
|
||||
intent.putExtra("play", play)
|
||||
intent.putExtra("pageIndex", pageIndex)
|
||||
intent.putExtra("startPos", startPos)
|
||||
LogUtils.d("ReadAloud", intent.toString())
|
||||
try {
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
} catch (e: Exception) {
|
||||
|
Loading…
Reference in New Issue
Block a user