optimise plugin load

pull/21/head
fengyuecanzhu 3 years ago
parent 85fac3f2d0
commit b195703351
  1. 11
      app/src/main/java/xyz/fycz/myreader/util/utils/PluginUtils.kt

@ -3,6 +3,10 @@ package xyz.fycz.myreader.util.utils
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import dalvik.system.DexClassLoader import dalvik.system.DexClassLoader
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import xyz.fycz.dynamic.AppParam import xyz.fycz.dynamic.AppParam
import xyz.fycz.dynamic.IAppLoader import xyz.fycz.dynamic.IAppLoader
import xyz.fycz.myreader.application.App import xyz.fycz.myreader.application.App
@ -33,13 +37,14 @@ object PluginUtils {
SharedPreUtils.getInstance().getString("pluginConfigUrl", DEFAULT_PLUGIN_CONFIG_URL) SharedPreUtils.getInstance().getString("pluginConfigUrl", DEFAULT_PLUGIN_CONFIG_URL)
var config: PluginConfig? = null var config: PluginConfig? = null
Coroutine.async { Coroutine.async {
val oldConfig = GSON.fromJsonObject<PluginConfig>(
SharedPreUtils.getInstance().getString("pluginConfig")
) ?: PluginConfig("dynamic.dex", 100)
launch { loadAppLoader(App.getmContext(), config) }
val configJson = getProxyClient().newCallResponseBody { val configJson = getProxyClient().newCallResponseBody {
url(pluginConfigUrl) url(pluginConfigUrl)
}.text() }.text()
config = GSON.fromJsonObject<PluginConfig>(configJson) config = GSON.fromJsonObject<PluginConfig>(configJson)
val oldConfig = GSON.fromJsonObject<PluginConfig>(
SharedPreUtils.getInstance().getString("pluginConfig")
) ?: PluginConfig("dynamic.dex", 100)
if (config != null) { if (config != null) {
if (config!!.versionCode > oldConfig.versionCode) { if (config!!.versionCode > oldConfig.versionCode) {
downloadPlugin(config!!) downloadPlugin(config!!)

Loading…
Cancel
Save