Fix plugin load bug

master^2
fengyuecanzhu 2 years ago
parent 4b708a978f
commit 7bd5e1d0c4
No known key found for this signature in database
GPG Key ID: 04B78AD06A9D6E6C
  1. 2
      app/src/main/java/xyz/fycz/myreader/entity/PluginConfig.kt
  2. 28
      app/src/main/java/xyz/fycz/myreader/util/utils/PluginUtils.kt

@ -31,5 +31,5 @@ data class PluginConfig(
val changelog: String val changelog: String
) { ) {
constructor(name: String, versionCode: Int) : constructor(name: String, versionCode: Int) :
this(name, versionCode, "", "", "", "") this(name, versionCode, "", "", "", "插件加载失败,当前为默认插件")
} }

@ -58,24 +58,27 @@ object PluginUtils {
val oldConfig = GSON.fromJsonObject<PluginConfig>( val oldConfig = GSON.fromJsonObject<PluginConfig>(
SharedPreUtils.getInstance().getString("pluginConfig") SharedPreUtils.getInstance().getString("pluginConfig")
) ?: PluginConfig("dynamic.dex", 100) ) ?: PluginConfig("dynamic.dex", 100)
launch { loadAppLoader(App.getmContext(), config) } try {
val configJson = getProxyClient().newCallResponseBody { val configJson = getProxyClient().newCallResponseBody(5) {
url(pluginConfigUrl) url(pluginConfigUrl)
}.text() }.text()
config = GSON.fromJsonObject<PluginConfig>(configJson) config = GSON.fromJsonObject<PluginConfig>(configJson)
if (config != null) {
if (config!!.versionCode > oldConfig.versionCode) { if (config!!.versionCode > oldConfig.versionCode) {
downloadPlugin(config!!) downloadPlugin(config!!)
SharedPreUtils.getInstance().putString("pluginConfig", configJson)
} }
} else { } catch (e: Exception) {
config = oldConfig config = oldConfig
e.printStackTrace()
errorMsg = e.stackTraceToString()
} }
if (config!!.md5.lowercase(Locale.getDefault()) kotlin.runCatching {
!= getPluginMD5(config!!)?.lowercase(Locale.getDefault()) if (config!!.md5.lowercase(Locale.getDefault())
) { != getPluginMD5(config!!)?.lowercase(Locale.getDefault())
downloadPlugin(config!!) ) {
downloadPlugin(config!!)
}
} }
Log.d(TAG, config!!.toString())
}.onSuccess { }.onSuccess {
loadAppLoader(App.getmContext(), config) loadAppLoader(App.getmContext(), config)
} }
@ -117,6 +120,7 @@ object PluginUtils {
hasLoad = true hasLoad = true
loadSuccess = true loadSuccess = true
} }
SharedPreUtils.getInstance().putString("pluginConfig", GSON.toJson(config))
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
errorMsg = e.stackTraceToString() errorMsg = e.stackTraceToString()

Loading…
Cancel
Save