manager: Fallback allows developers to override user preferences for the selected WebUI engine
- Because the WebUI can cause some problems, the automatic fetching of the
This commit is contained in:
@@ -72,8 +72,6 @@ import com.sukisu.ultra.ui.theme.CardConfig.cardElevation
|
|||||||
import com.sukisu.ultra.ui.webui.WebUIXActivity
|
import com.sukisu.ultra.ui.webui.WebUIXActivity
|
||||||
import com.dergoogler.mmrl.platform.Platform
|
import com.dergoogler.mmrl.platform.Platform
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import com.dergoogler.mmrl.platform.model.ModuleConfig
|
|
||||||
import com.dergoogler.mmrl.platform.model.ModuleConfig.Companion.asModuleConfig
|
|
||||||
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@@ -384,19 +382,6 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
|||||||
.putExtra("id", id)
|
.putExtra("id", id)
|
||||||
.putExtra("name", name)
|
.putExtra("name", name)
|
||||||
|
|
||||||
val config = id.asModuleConfig
|
|
||||||
val engine = config.getWebuiEngine(context)
|
|
||||||
if (engine != null) {
|
|
||||||
webUILauncher.launch(
|
|
||||||
when (config.getWebuiEngine(context)) {
|
|
||||||
"wx" -> wxEngine
|
|
||||||
"ksu" -> ksuEngine
|
|
||||||
else -> ksuEngine
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return@ModuleList
|
|
||||||
}
|
|
||||||
|
|
||||||
webUILauncher.launch(
|
webUILauncher.launch(
|
||||||
if (prefs.getBoolean("use_webuix", true) && Platform.isAlive) {
|
if (prefs.getBoolean("use_webuix", true) && Platform.isAlive) {
|
||||||
wxEngine
|
wxEngine
|
||||||
@@ -917,8 +902,7 @@ fun ModuleItemPreview() {
|
|||||||
updateJson = "",
|
updateJson = "",
|
||||||
hasWebUi = false,
|
hasWebUi = false,
|
||||||
hasActionScript = false,
|
hasActionScript = false,
|
||||||
dirId = "dirId",
|
dirId = "dirId"
|
||||||
config = ModuleConfig()
|
|
||||||
)
|
)
|
||||||
ModuleItem(EmptyDestinationsNavigator, module, "", {}, {}, {}, {})
|
ModuleItem(EmptyDestinationsNavigator, module, "", {}, {}, {}, {})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ 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
|
||||||
@@ -18,8 +17,6 @@ import org.json.JSONObject
|
|||||||
import java.text.Collator
|
import java.text.Collator
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import com.dergoogler.mmrl.platform.model.ModuleConfig
|
|
||||||
import com.dergoogler.mmrl.platform.model.ModuleConfig.Companion.asModuleConfig
|
|
||||||
|
|
||||||
class ModuleViewModel : ViewModel() {
|
class ModuleViewModel : ViewModel() {
|
||||||
|
|
||||||
@@ -43,7 +40,6 @@ 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)
|
||||||
var config: ModuleConfig? = null,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var isRefreshing by mutableStateOf(false)
|
var isRefreshing by mutableStateOf(false)
|
||||||
@@ -91,14 +87,13 @@ class ModuleViewModel : ViewModel() {
|
|||||||
.asSequence()
|
.asSequence()
|
||||||
.map { array.getJSONObject(it) }
|
.map { array.getJSONObject(it) }
|
||||||
.map { obj ->
|
.map { obj ->
|
||||||
val id = obj.getString("id")
|
|
||||||
ModuleInfo(
|
ModuleInfo(
|
||||||
id,
|
obj.getString("id"),
|
||||||
obj.optString("name", "Unknown"),
|
obj.optString("name"),
|
||||||
obj.optString("author", "Unknown"),
|
obj.optString("author", "Unknown"),
|
||||||
obj.optString("version", "Unknown"),
|
obj.optString("version", "Unknown"),
|
||||||
obj.optInt("versionCode", 0),
|
obj.optInt("versionCode", 0),
|
||||||
obj.optString("description", ""),
|
obj.optString("description"),
|
||||||
obj.getBoolean("enabled"),
|
obj.getBoolean("enabled"),
|
||||||
obj.getBoolean("update"),
|
obj.getBoolean("update"),
|
||||||
obj.getBoolean("remove"),
|
obj.getBoolean("remove"),
|
||||||
@@ -108,19 +103,6 @@ class ModuleViewModel : ViewModel() {
|
|||||||
obj.getString("dir_id")
|
obj.getString("dir_id")
|
||||||
)
|
)
|
||||||
}.toList()
|
}.toList()
|
||||||
launch {
|
|
||||||
// load WebUI config
|
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user