From b1957033518ad49e7fe2be1fa0110bcfefee68e2 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Sun, 24 Apr 2022 19:47:00 +0800 Subject: [PATCH] optimise plugin load --- .../java/xyz/fycz/myreader/util/utils/PluginUtils.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/xyz/fycz/myreader/util/utils/PluginUtils.kt b/app/src/main/java/xyz/fycz/myreader/util/utils/PluginUtils.kt index 7a2cf80..9916456 100644 --- a/app/src/main/java/xyz/fycz/myreader/util/utils/PluginUtils.kt +++ b/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.util.Log 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.IAppLoader import xyz.fycz.myreader.application.App @@ -33,13 +37,14 @@ object PluginUtils { SharedPreUtils.getInstance().getString("pluginConfigUrl", DEFAULT_PLUGIN_CONFIG_URL) var config: PluginConfig? = null Coroutine.async { + val oldConfig = GSON.fromJsonObject( + SharedPreUtils.getInstance().getString("pluginConfig") + ) ?: PluginConfig("dynamic.dex", 100) + launch { loadAppLoader(App.getmContext(), config) } val configJson = getProxyClient().newCallResponseBody { url(pluginConfigUrl) }.text() config = GSON.fromJsonObject(configJson) - val oldConfig = GSON.fromJsonObject( - SharedPreUtils.getInstance().getString("pluginConfig") - ) ?: PluginConfig("dynamic.dex", 100) if (config != null) { if (config!!.versionCode > oldConfig.versionCode) { downloadPlugin(config!!)