From 7bd5e1d0c46d90f88f9c2d809406aa10b85aa4c5 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Thu, 11 Aug 2022 17:35:20 +0800 Subject: [PATCH] Fix plugin load bug --- .../xyz/fycz/myreader/entity/PluginConfig.kt | 2 +- .../fycz/myreader/util/utils/PluginUtils.kt | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/xyz/fycz/myreader/entity/PluginConfig.kt b/app/src/main/java/xyz/fycz/myreader/entity/PluginConfig.kt index f6f18c4..2ed1685 100644 --- a/app/src/main/java/xyz/fycz/myreader/entity/PluginConfig.kt +++ b/app/src/main/java/xyz/fycz/myreader/entity/PluginConfig.kt @@ -31,5 +31,5 @@ data class PluginConfig( val changelog: String ) { constructor(name: String, versionCode: Int) : - this(name, versionCode, "", "", "", "") + this(name, versionCode, "", "", "", "插件加载失败,当前为默认插件") } 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 ba9e704..e6252ad 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 @@ -58,24 +58,27 @@ object PluginUtils { 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) - if (config != null) { + try { + val configJson = getProxyClient().newCallResponseBody(5) { + url(pluginConfigUrl) + }.text() + config = GSON.fromJsonObject(configJson) if (config!!.versionCode > oldConfig.versionCode) { downloadPlugin(config!!) - SharedPreUtils.getInstance().putString("pluginConfig", configJson) } - } else { + } catch (e: Exception) { config = oldConfig + e.printStackTrace() + errorMsg = e.stackTraceToString() } - if (config!!.md5.lowercase(Locale.getDefault()) - != getPluginMD5(config!!)?.lowercase(Locale.getDefault()) - ) { - downloadPlugin(config!!) + kotlin.runCatching { + if (config!!.md5.lowercase(Locale.getDefault()) + != getPluginMD5(config!!)?.lowercase(Locale.getDefault()) + ) { + downloadPlugin(config!!) + } } + Log.d(TAG, config!!.toString()) }.onSuccess { loadAppLoader(App.getmContext(), config) } @@ -117,6 +120,7 @@ object PluginUtils { hasLoad = true loadSuccess = true } + SharedPreUtils.getInstance().putString("pluginConfig", GSON.toJson(config)) } catch (e: Exception) { e.printStackTrace() errorMsg = e.stackTraceToString()