manager: Fix remote template fetch error.

This commit is contained in:
weishu
2023-10-21 15:29:26 +08:00
parent 54a705d8dc
commit 10b31bd09a

View File

@@ -88,10 +88,10 @@ class TemplateViewModel : ViewModel() {
}
private fun fetchRemoteTemplates() {
runCatching {
OkHttpClient().newCall(
Request.Builder().url(TEMPLATE_INDEX_URL).build()
).runCatching {
execute().use { response ->
).execute().use { response ->
if (!response.isSuccessful) {
return
}
@@ -125,9 +125,7 @@ private fun fetchRemoteTemplates() {
}
}
}
}.onFailure {
Log.e(TAG, "fetchRemoteTemplates error", it)
}
}.onFailure { Log.e(TAG, "fetchRemoteTemplates: $it", it) }
}
@Suppress("UNCHECKED_CAST")
@@ -168,7 +166,7 @@ private fun fromJSON(templateJson: JSONObject): TemplateViewModel.TemplateInfo?
id = templateJson.getString("id"),
name = templateJson.getString("name"),
description = templateJson.getString("description"),
local = templateJson.getBoolean("local"),
local = templateJson.optBoolean("local"),
namespace = Natives.Profile.Namespace.valueOf(
templateJson.getString("namespace").uppercase()
).ordinal,