mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-11 21:30:11 +08:00
Plugin Center view
This commit is contained in:
parent
bd2ce8f771
commit
7d9ffb8c71
@ -57,7 +57,9 @@ dependencies {
|
|||||||
api(group = "com.jfoenix", name = "jfoenix", version = "9.0.8")
|
api(group = "com.jfoenix", name = "jfoenix", version = "9.0.8")
|
||||||
|
|
||||||
testApi(project(":mirai-console"))
|
testApi(project(":mirai-console"))
|
||||||
|
testApi(kotlinx("coroutines-core", Versions.Kotlin.coroutines))
|
||||||
testApi(group = "org.yaml", name = "snakeyaml", version = "1.25")
|
testApi(group = "org.yaml", name = "snakeyaml", version = "1.25")
|
||||||
|
testApi("net.mamoe:mirai-core-jvm:${Versions.Mirai.core}")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||||
|
@ -125,6 +125,29 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun checkLatest(plugin: PluginModel) {
|
||||||
|
pluginList.forEach {
|
||||||
|
if (it.name == plugin.name && it.author == plugin.author) {
|
||||||
|
if (plugin.version > it.version) {
|
||||||
|
it.latest = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return `true` when command is ambiguous
|
||||||
|
*/
|
||||||
|
fun checkAmbiguous(plugin: PluginModel) : Boolean {
|
||||||
|
plugin.insight?.commands?.forEach { name ->
|
||||||
|
CommandManager.commands.forEach {
|
||||||
|
if (name == it.name) return true
|
||||||
|
}
|
||||||
|
} ?: return false
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GraphicalLoginSolver : LoginSolver() {
|
class GraphicalLoginSolver : LoginSolver() {
|
||||||
|
@ -3,6 +3,7 @@ package net.mamoe.mirai.console.graphical.model
|
|||||||
import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject
|
import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject
|
||||||
import javafx.beans.property.SimpleBooleanProperty
|
import javafx.beans.property.SimpleBooleanProperty
|
||||||
import javafx.beans.property.SimpleStringProperty
|
import javafx.beans.property.SimpleStringProperty
|
||||||
|
import net.mamoe.mirai.console.center.PluginCenter
|
||||||
import net.mamoe.mirai.console.plugins.PluginDescription
|
import net.mamoe.mirai.console.plugins.PluginDescription
|
||||||
import tornadofx.getValue
|
import tornadofx.getValue
|
||||||
import tornadofx.setValue
|
import tornadofx.setValue
|
||||||
@ -11,7 +12,8 @@ class PluginModel(
|
|||||||
val name: String,
|
val name: String,
|
||||||
val version: String,
|
val version: String,
|
||||||
val author: String,
|
val author: String,
|
||||||
val description: String
|
val description: String,
|
||||||
|
var insight: PluginCenter.PluginInsight? = null
|
||||||
) : RecursiveTreeObject<PluginModel>() {
|
) : RecursiveTreeObject<PluginModel>() {
|
||||||
constructor(plugin: PluginDescription) : this(plugin.name, plugin.version, plugin.author, plugin.info)
|
constructor(plugin: PluginDescription) : this(plugin.name, plugin.version, plugin.author, plugin.info)
|
||||||
|
|
||||||
@ -22,4 +24,7 @@ class PluginModel(
|
|||||||
|
|
||||||
val enabledProperty = SimpleBooleanProperty(this, "enabledProperty")
|
val enabledProperty = SimpleBooleanProperty(this, "enabledProperty")
|
||||||
var enabled by enabledProperty
|
var enabled by enabledProperty
|
||||||
|
|
||||||
|
val latestProperty = SimpleBooleanProperty(this, "latestProperty", true)
|
||||||
|
var latest by latestProperty
|
||||||
}
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
package net.mamoe.mirai.console.graphical.view
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXTreeTableColumn
|
||||||
|
import javafx.collections.ObservableList
|
||||||
|
import javafx.geometry.Pos
|
||||||
|
import javafx.scene.control.TreeTableCell
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import net.mamoe.mirai.console.center.CuiPluginCenter
|
||||||
|
import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
|
||||||
|
import net.mamoe.mirai.console.graphical.model.PluginModel
|
||||||
|
import net.mamoe.mirai.console.graphical.stylesheet.PluginViewStyleSheet
|
||||||
|
import net.mamoe.mirai.console.graphical.util.jfxButton
|
||||||
|
import net.mamoe.mirai.console.graphical.util.jfxTreeTableView
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
|
class PluginsCenterView : View() {
|
||||||
|
|
||||||
|
private val controller = find<MiraiGraphicalUIController>()
|
||||||
|
private val center = CuiPluginCenter
|
||||||
|
private val plugins: ObservableList<PluginModel> by lazy(::fetch)
|
||||||
|
|
||||||
|
override val root = jfxTreeTableView(plugins) {
|
||||||
|
|
||||||
|
addStylesheet(PluginViewStyleSheet::class)
|
||||||
|
|
||||||
|
isShowRoot = false
|
||||||
|
columns.addAll(
|
||||||
|
JFXTreeTableColumn<PluginModel, String>("插件名").apply {
|
||||||
|
prefWidthProperty().bind(this@jfxTreeTableView.widthProperty().multiply(0.1))
|
||||||
|
|
||||||
|
setCellValueFactory {
|
||||||
|
return@setCellValueFactory it.value.value.nameProperty
|
||||||
|
}
|
||||||
|
},
|
||||||
|
JFXTreeTableColumn<PluginModel, String>("版本").apply {
|
||||||
|
prefWidthProperty().bind(this@jfxTreeTableView.widthProperty().multiply(0.1))
|
||||||
|
|
||||||
|
setCellValueFactory {
|
||||||
|
return@setCellValueFactory it.value.value.versionProperty
|
||||||
|
}
|
||||||
|
},
|
||||||
|
JFXTreeTableColumn<PluginModel, String>("作者").apply {
|
||||||
|
prefWidthProperty().bind(this@jfxTreeTableView.widthProperty().multiply(0.1))
|
||||||
|
|
||||||
|
setCellValueFactory {
|
||||||
|
return@setCellValueFactory it.value.value.authorProperty
|
||||||
|
}
|
||||||
|
},
|
||||||
|
JFXTreeTableColumn<PluginModel, String>("介绍").apply {
|
||||||
|
prefWidthProperty().bind(this@jfxTreeTableView.widthProperty().multiply(0.48))
|
||||||
|
|
||||||
|
setCellValueFactory {
|
||||||
|
return@setCellValueFactory it.value.value.descriptionProperty
|
||||||
|
}
|
||||||
|
},
|
||||||
|
JFXTreeTableColumn<PluginModel, PluginModel>("操作").apply {
|
||||||
|
prefWidthProperty().bind(this@jfxTreeTableView.widthProperty().multiply(0.2))
|
||||||
|
|
||||||
|
setCellValueFactory { return@setCellValueFactory it.value.valueProperty() }
|
||||||
|
|
||||||
|
setCellFactory {
|
||||||
|
return@setCellFactory object : TreeTableCell<PluginModel, PluginModel>() {
|
||||||
|
override fun updateItem(item: PluginModel?, empty: Boolean) {
|
||||||
|
if (item != null && !empty) {
|
||||||
|
graphic = hbox {
|
||||||
|
|
||||||
|
spacing = 15.0
|
||||||
|
alignment = Pos.CENTER
|
||||||
|
|
||||||
|
jfxButton("详情") {
|
||||||
|
action { detail(item) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
jfxButton("下载") {
|
||||||
|
action { download(item) }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
text = ""
|
||||||
|
} else {
|
||||||
|
graphic = null
|
||||||
|
text = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetch(): ObservableList<PluginModel> =
|
||||||
|
runAsync {
|
||||||
|
val ret = observableListOf<PluginModel>()
|
||||||
|
runBlocking {
|
||||||
|
var page = 1
|
||||||
|
while (true) {
|
||||||
|
val map = center.fetchPlugin(page++)
|
||||||
|
if (map.isEmpty()) return@runBlocking
|
||||||
|
map.forEach {
|
||||||
|
ret.add(
|
||||||
|
PluginModel(
|
||||||
|
it.value.name,
|
||||||
|
it.value.version,
|
||||||
|
it.value.author,
|
||||||
|
it.value.description,
|
||||||
|
it.value
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@runAsync ret
|
||||||
|
}.get()
|
||||||
|
|
||||||
|
private fun detail(pluginModel: PluginModel) {
|
||||||
|
//to show pluginModel.insight
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun download(pluginModel: PluginModel) {
|
||||||
|
// controller.checkAmbiguous(pluginModel)
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -120,6 +120,8 @@ class PrimaryView : View() {
|
|||||||
|
|
||||||
fixedTab("Plugins").content = find<PluginsView>().root
|
fixedTab("Plugins").content = find<PluginsView>().root
|
||||||
|
|
||||||
|
fixedTab("Plugins Center").content = find<PluginsCenterView>().root
|
||||||
|
|
||||||
fixedTab("Settings").content = find<SettingsView>().root
|
fixedTab("Settings").content = find<SettingsView>().root
|
||||||
|
|
||||||
fixedTab("Login").content = find<LoginView>().root
|
fixedTab("Login").content = find<LoginView>().root
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.mamoe.mirai.console.center
|
package net.mamoe.mirai.console.center
|
||||||
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.JsonArray
|
import com.google.gson.JsonArray
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
@ -24,20 +23,20 @@ object CuiPluginCenter: PluginCenter{
|
|||||||
if(plugins == null){
|
if(plugins == null){
|
||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
if(it > plugins!!.size()){
|
if(it >= plugins!!.size()){
|
||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
val info = plugins!![it]
|
val info = plugins!![it]
|
||||||
with(info.asJsonObject){
|
with(info.asJsonObject){
|
||||||
map[this.get("name").asString] = PluginCenter.PluginInsight(
|
map[this.get("name").asString] = PluginCenter.PluginInsight(
|
||||||
this.get("name").asString,
|
this.get("name")?.asString ?: "",
|
||||||
this.get("version").asString,
|
this.get("version")?.asString ?: "",
|
||||||
this.get("core").asString,
|
this.get("core")?.asString ?: "",
|
||||||
this.get("console").asString,
|
this.get("console")?.asString ?: "",
|
||||||
this.get("author").asString,
|
this.get("author")?.asString ?: "",
|
||||||
this.get("contact").asString,
|
this.get("contact")?.asString ?: "",
|
||||||
this.get("tags").asJsonArray.map { it.asString },
|
this.get("tags")?.asJsonArray?.map { it.asString } ?: arrayListOf(),
|
||||||
this.get("commands").asJsonArray.map { it.asString }
|
this.get("commands")?.asJsonArray?.map { it.asString } ?: arrayListOf()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user