From c9b1dac5677bc4f4f1a862eba700d0d3ff062409 Mon Sep 17 00:00:00 2001 From: ryoii Date: Fri, 3 Apr 2020 17:28:35 +0800 Subject: [PATCH] Check plugins update --- .../controller/MiraiGraphicalUIController.kt | 2 +- .../graphical/view/PluginsCenterView.kt | 20 ++++++------ .../console/graphical/view/PluginsView.kt | 31 +++++++++++++------ 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt index 1b992d21f..5b493625e 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt @@ -125,7 +125,7 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI { } } - fun checkLatest(plugin: PluginModel) { + fun checkUpdate(plugin: PluginModel) { pluginList.forEach { if (it.name == plugin.name && it.author == plugin.author) { if (plugin.version > it.version) { diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsCenterView.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsCenterView.kt index 4ef33ba7b..15cc732ee 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsCenterView.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsCenterView.kt @@ -99,15 +99,17 @@ class PluginsCenterView : View() { 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 - ) - ) + with(PluginModel( + it.value.name, + it.value.version, + it.value.author, + it.value.description, + it.value + )) { + ret.add(this) + controller.checkUpdate(this) + controller.checkAmbiguous(this) + } } } } diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsView.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsView.kt index a5d229125..2753ad9cf 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsView.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsView.kt @@ -1,12 +1,15 @@ package net.mamoe.mirai.console.graphical.view import com.jfoenix.controls.JFXTreeTableColumn +import javafx.scene.control.TreeTableCell 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.View import tornadofx.addStylesheet +import tornadofx.visibleWhen class PluginsView : View() { @@ -50,15 +53,25 @@ class PluginsView : View() { JFXTreeTableColumn("操作").apply { prefWidthProperty().bind(this@jfxTreeTableView.widthProperty().multiply(0.08)) -// setCellValueFactory { return@setCellValueFactory it.value.valueProperty() } -// -// setCellFactory { -// return@setCellFactory object : TreeTableCell() { -// override fun updateItem(item: PluginModel?, empty: Boolean) { -// -// } -// } -// } + setCellValueFactory { return@setCellValueFactory it.value.valueProperty() } + + setCellFactory { + return@setCellFactory object : TreeTableCell() { + override fun updateItem(item: PluginModel?, empty: Boolean) { + if (item != null && !empty) { + graphic = jfxButton("更新") { + visibleWhen(item.expiredProperty) + + // to do update + } + text = "" + } else { + graphic = null + text = "" + } + } + } + } } ) }