manager: Adding Vacancies to WeiUI Configuration and Implementing Asynchronous Loading
- Upgrade agp version to 8.10.1
This commit is contained in:
@@ -10,6 +10,7 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import com.sukisu.ultra.ui.util.HanziToPinyin
|
import com.sukisu.ultra.ui.util.HanziToPinyin
|
||||||
import com.sukisu.ultra.ui.util.listModules
|
import com.sukisu.ultra.ui.util.listModules
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
@@ -42,7 +43,7 @@ class ModuleViewModel : ViewModel() {
|
|||||||
val hasWebUi: Boolean,
|
val hasWebUi: Boolean,
|
||||||
val hasActionScript: Boolean,
|
val hasActionScript: Boolean,
|
||||||
val dirId: String, // real module id (dir name)
|
val dirId: String, // real module id (dir name)
|
||||||
val config: ModuleConfig,
|
var config: ModuleConfig? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
var isRefreshing by mutableStateOf(false)
|
var isRefreshing by mutableStateOf(false)
|
||||||
@@ -91,32 +92,40 @@ class ModuleViewModel : ViewModel() {
|
|||||||
.map { array.getJSONObject(it) }
|
.map { array.getJSONObject(it) }
|
||||||
.map { obj ->
|
.map { obj ->
|
||||||
val id = obj.getString("id")
|
val id = obj.getString("id")
|
||||||
val config = id.asModuleConfig
|
|
||||||
ModuleInfo(
|
ModuleInfo(
|
||||||
id,
|
id,
|
||||||
config.name ?: obj.optString("name"),
|
obj.optString("name", "Unknown"),
|
||||||
obj.optString("author", "Unknown"),
|
obj.optString("author", "Unknown"),
|
||||||
obj.optString("version", "Unknown"),
|
obj.optString("version", "Unknown"),
|
||||||
obj.optInt("versionCode", 0),
|
obj.optInt("versionCode", 0),
|
||||||
config.description ?: obj.optString("description"),
|
obj.optString("description", ""),
|
||||||
obj.getBoolean("enabled"),
|
obj.getBoolean("enabled"),
|
||||||
obj.getBoolean("update"),
|
obj.getBoolean("update"),
|
||||||
obj.getBoolean("remove"),
|
obj.getBoolean("remove"),
|
||||||
obj.optString("updateJson"),
|
obj.optString("updateJson"),
|
||||||
obj.optBoolean("web"),
|
obj.optBoolean("web"),
|
||||||
obj.optBoolean("action"),
|
obj.optBoolean("action"),
|
||||||
obj.getString("dir_id"),
|
obj.getString("dir_id")
|
||||||
config
|
|
||||||
)
|
)
|
||||||
}.toList()
|
}.toList()
|
||||||
|
launch {
|
||||||
|
modules.forEach { module ->
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
module.config = module.id.asModuleConfig
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Failed to load config for module ${module.id}", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isNeedRefresh = false
|
isNeedRefresh = false
|
||||||
}.onFailure { e ->
|
}.onFailure { e ->
|
||||||
Log.e(TAG, "fetchModuleList: ", e)
|
Log.e(TAG, "fetchModuleList: ", e)
|
||||||
isRefreshing = false
|
isRefreshing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// when both old and new is kotlin.collections.EmptyList
|
|
||||||
// moduleList update will don't trigger
|
|
||||||
if (oldModuleList === modules) {
|
if (oldModuleList === modules) {
|
||||||
isRefreshing = false
|
isRefreshing = false
|
||||||
}
|
}
|
||||||
@@ -134,7 +143,6 @@ class ModuleViewModel : ViewModel() {
|
|||||||
if (m.updateJson.isEmpty() || m.remove || m.update || !m.enabled) {
|
if (m.updateJson.isEmpty() || m.remove || m.update || !m.enabled) {
|
||||||
return empty
|
return empty
|
||||||
}
|
}
|
||||||
// download updateJson
|
|
||||||
val result = kotlin.runCatching {
|
val result = kotlin.runCatching {
|
||||||
val url = m.updateJson
|
val url = m.updateJson
|
||||||
Log.i(TAG, "checkUpdate url: $url")
|
Log.i(TAG, "checkUpdate url: $url")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "8.10.0"
|
agp = "8.10.1"
|
||||||
kotlin = "2.1.20"
|
kotlin = "2.1.20"
|
||||||
ksp = "2.1.20-2.0.0"
|
ksp = "2.1.20-2.0.0"
|
||||||
compose-bom = "2025.05.01"
|
compose-bom = "2025.05.01"
|
||||||
|
|||||||
Reference in New Issue
Block a user