优化
This commit is contained in:
@@ -28,6 +28,7 @@ import io.legado.app.help.RuleBigDataHelp
|
||||
import io.legado.app.help.book.BookHelp
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.config.ThemeConfig.applyDayNight
|
||||
import io.legado.app.help.config.ThemeConfig.initNightMode
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.help.http.Cronet
|
||||
import io.legado.app.help.http.ObsoleteUrlFactory
|
||||
@@ -55,27 +56,27 @@ class App : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
CrashHandler(this)
|
||||
LogUtils.init(this)
|
||||
LogUtils.d("App", "onCreate")
|
||||
if (isDebuggable) {
|
||||
ThreadUtils.setThreadAssertsDisabledForTesting(true)
|
||||
}
|
||||
oldConfig = Configuration(resources.configuration)
|
||||
//预下载Cronet so
|
||||
Cronet.preDownload()
|
||||
createNotificationChannels()
|
||||
LiveEventBus.config()
|
||||
.lifecycleObserverAlwaysActive(true)
|
||||
.autoClear(false)
|
||||
.enableLogger(BuildConfig.DEBUG || AppConfig.recordLog)
|
||||
.setLogger(EventLogger())
|
||||
applyDayNight(this)
|
||||
initNightMode()
|
||||
registerActivityLifecycleCallbacks(LifecycleHelp)
|
||||
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
|
||||
DefaultData.upVersion()
|
||||
AppFreezeMonitor.init(this)
|
||||
Coroutine.async {
|
||||
LogUtils.init(this@App)
|
||||
LogUtils.d("App", "onCreate")
|
||||
LogUtils.logDeviceInfo()
|
||||
//预下载Cronet so
|
||||
Cronet.preDownload()
|
||||
createNotificationChannels()
|
||||
LiveEventBus.config()
|
||||
.lifecycleObserverAlwaysActive(true)
|
||||
.autoClear(false)
|
||||
.enableLogger(BuildConfig.DEBUG || AppConfig.recordLog)
|
||||
.setLogger(EventLogger())
|
||||
DefaultData.upVersion()
|
||||
AppFreezeMonitor.init(this@App)
|
||||
URL.setURLStreamHandlerFactory(ObsoleteUrlFactory(okHttpClient))
|
||||
launch { installGmsTlsProvider(appCtx) }
|
||||
RhinoScriptEngine
|
||||
|
||||
@@ -57,7 +57,7 @@ object ThemeConfig {
|
||||
postEvent(EventBus.RECREATE, "")
|
||||
}
|
||||
|
||||
private fun initNightMode() {
|
||||
fun initNightMode() {
|
||||
val targetMode =
|
||||
if (AppConfig.isNightTheme) {
|
||||
AppCompatDelegate.MODE_NIGHT_YES
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.legado.app.BuildConfig
|
||||
import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.globalExecutor
|
||||
import splitties.init.appCtx
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
@@ -26,7 +27,9 @@ object LogUtils {
|
||||
val logTimeFormat by lazy { SimpleDateFormat(TIME_PATTERN) }
|
||||
|
||||
fun init(context: Context) {
|
||||
fileHandler = createFileHandler(context)
|
||||
fileHandler = createFileHandler(context)?.also {
|
||||
logger.addHandler(it)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -46,11 +49,7 @@ object LogUtils {
|
||||
}
|
||||
|
||||
val logger: Logger by lazy {
|
||||
Logger.getLogger("Legado").apply {
|
||||
fileHandler?.let {
|
||||
addHandler(it)
|
||||
}
|
||||
}
|
||||
Logger.getLogger("Legado")
|
||||
}
|
||||
|
||||
private var fileHandler: FileHandler? = null
|
||||
@@ -59,10 +58,12 @@ object LogUtils {
|
||||
try {
|
||||
val root = context.externalCacheDir ?: return null
|
||||
val logFolder = FileUtils.createFolderIfNotExist(root, "logs")
|
||||
val expiredTime = System.currentTimeMillis() - 7.days.inWholeMilliseconds
|
||||
logFolder.listFiles()?.forEach {
|
||||
if (it.lastModified() < expiredTime || it.name.endsWith(".lck")) {
|
||||
it.delete()
|
||||
globalExecutor.execute {
|
||||
val expiredTime = System.currentTimeMillis() - 7.days.inWholeMilliseconds
|
||||
logFolder.listFiles()?.forEach {
|
||||
if (it.lastModified() < expiredTime || it.name.endsWith(".lck")) {
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
val date = getCurrentDateStr(TIME_PATTERN)
|
||||
|
||||
Reference in New Issue
Block a user