Skip to content

Commit c2141b8

Browse files
committed
1.优化新版本检查;2.添加删除插件功能
1 parent 497ff9a commit c2141b8

4 files changed

Lines changed: 68 additions & 21 deletions

File tree

src/main/java/com/xwintop/xJavaFxTool/controller/IndexController.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
import com.xwintop.xJavaFxTool.services.index.SystemSettingService;
1414
import com.xwintop.xJavaFxTool.utils.Config;
1515
import com.xwintop.xJavaFxTool.view.IndexView;
16+
import com.xwintop.xcore.javafx.FxApp;
17+
import com.xwintop.xcore.javafx.dialog.FxDialog;
1618
import com.xwintop.xcore.util.ConfigureUtil;
1719
import com.xwintop.xcore.util.HttpClientUtil;
1820
import com.xwintop.xcore.util.javafx.AlertUtil;
1921
import com.xwintop.xcore.util.javafx.JavaFxSystemUtil;
20-
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
2122
import javafx.application.Platform;
2223
import javafx.event.ActionEvent;
2324
import javafx.fxml.FXML;
2425
import javafx.fxml.FXMLLoader;
25-
import javafx.scene.Parent;
2626
import javafx.scene.control.Menu;
2727
import javafx.scene.control.MenuItem;
2828
import javafx.scene.control.Tab;
@@ -221,9 +221,17 @@ private void addLogConsoleAction(ActionEvent event) {
221221

222222
@FXML
223223
private void pluginManageAction() throws Exception {
224-
FXMLLoader fXMLLoader = PluginManageController.getFXMLLoader();
225-
Parent root = fXMLLoader.load();
226-
JavaFxViewUtil.openNewWindow(bundle.getString("plugin_manage"), root);
224+
// FXMLLoader fXMLLoader = PluginManageController.getFXMLLoader();
225+
// Parent root = fXMLLoader.load();
226+
// JavaFxViewUtil.openNewWindow(bundle.getString("plugin_manage"), root);
227+
new FxDialog<PluginManageController>()
228+
.setBodyFxml(PluginManageController.FXML)
229+
.setOwner(FxApp.primaryStage)
230+
.setResizable(true)
231+
.setTitle(XJavaFxToolApplication.RESOURCE_BUNDLE.getString("plugin_manage"))
232+
.setPrefWidth(800)
233+
.withStage(stage -> stage.setOnCloseRequest(event -> loadPlugins()))
234+
.show();
227235
}
228236

229237
@FXML

src/main/java/com/xwintop/xJavaFxTool/controller/index/PluginManageController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,18 @@ private void afterDownload(Map<String, String> dataRow, Button downloadButton, P
146146

147147
private void initEvent() {
148148
// 右键菜单
149-
MenuItem mnuSavePluginConfig = new MenuItem("保存配置");
150-
mnuSavePluginConfig.setOnAction(ev -> {
149+
ContextMenu contextMenu = new ContextMenu();
150+
JavaFxViewUtil.addMenuItem(contextMenu,"保存配置", actionEvent -> {
151151
try {
152152
PluginManager.getInstance().saveToFile();
153153
TooltipUtil.showToast("保存配置成功");
154154
} catch (Exception ex) {
155155
log.error("保存插件配置失败", ex);
156156
}
157157
});
158-
ContextMenu contextMenu = new ContextMenu(mnuSavePluginConfig);
158+
JavaFxViewUtil.addMenuItem(contextMenu,"删除插件", actionEvent -> {
159+
pluginManageService.deletePlugin();
160+
});
159161
pluginDataTableView.setContextMenu(contextMenu);
160162
// 搜索
161163
selectPluginTextField.textProperty().addListener((_ob, _old, _new) -> pluginManageService.searchPlugin(_new));

src/main/java/com/xwintop/xJavaFxTool/services/index/PluginManageService.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.xwintop.xJavaFxTool.AppException;
44
import com.xwintop.xJavaFxTool.controller.index.PluginManageController;
5+
import com.xwintop.xJavaFxTool.event.AppEvents;
6+
import com.xwintop.xJavaFxTool.event.PluginEvent;
57
import com.xwintop.xJavaFxTool.model.PluginJarInfo;
68
import com.xwintop.xJavaFxTool.plugin.PluginManager;
79
import com.xwintop.xcore.javafx.dialog.FxAlerts;
@@ -11,8 +13,11 @@
1113
import lombok.Getter;
1214
import lombok.Setter;
1315
import lombok.extern.slf4j.Slf4j;
16+
import org.apache.commons.io.FileUtils;
17+
import org.apache.commons.lang3.BooleanUtils;
1418
import org.apache.commons.lang3.StringUtils;
1519

20+
import java.io.IOException;
1621
import java.util.HashMap;
1722
import java.util.Map;
1823
import java.util.function.Consumer;
@@ -139,4 +144,36 @@ public static boolean isPluginEnabled(String fileName) {
139144
Boolean isEnable = pluginJarInfo.getIsEnable();
140145
return isEnable != null && isEnable;
141146
}
147+
148+
//删除插件
149+
public void deletePlugin() {
150+
Integer index = pluginManageController.getPluginDataTableView().getSelectionModel().getSelectedIndex();
151+
if (index == null || index == -1) {
152+
return;
153+
}
154+
Map<String, String> dataRow = pluginManageController.getOriginPluginData().get(index);
155+
String jarName = dataRow.get("jarName");
156+
PluginJarInfo pluginJarInfo = this.pluginManager.getPlugin(jarName);
157+
if(BooleanUtils.isNotTrue(pluginJarInfo.getIsDownload())){
158+
FxAlerts.info("提示",pluginJarInfo.getName() + " 该插件未下载");
159+
return;
160+
}
161+
if (!FxAlerts.confirmYesNo("删除插件", String.format("确定要删除插件 %s 吗?", pluginJarInfo.getName()))) {
162+
return;
163+
}
164+
if (pluginJarInfo != null) {
165+
try {
166+
FileUtils.delete(pluginJarInfo.getFile());
167+
dataRow.put("isEnableTableColumn", "false");
168+
dataRow.put("isDownloadTableColumn", "下载");
169+
pluginJarInfo.setIsEnable(false);
170+
pluginJarInfo.setIsDownload(false);
171+
PluginManager.getInstance().saveToFile();
172+
pluginManageController.getPluginDataTableView().refresh();
173+
AppEvents.fire(new PluginEvent(PluginEvent.PLUGIN_DOWNLOADED, pluginJarInfo));
174+
} catch (IOException e) {
175+
log.error("删除插件失败", e);
176+
}
177+
}
178+
}
142179
}

src/main/java/com/xwintop/xJavaFxTool/utils/VersionChecker.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
@Slf4j
1818
public class VersionChecker {
1919
public static void checkNewVersion() {
20-
String json = HttpUtil.get("https://gitee.com/api/v5/repos/xwintop/xJavaFxTool/releases/latest");
21-
JSONObject node = JSON.parseObject(json);
22-
final String latestVersion = node.getString("tag_name");
23-
final String features = node.getString("body");
24-
if (isLargerThanCurrent(latestVersion)) {
25-
final String content = new StringBuilder()
26-
.append("版本名:").append(node.getString("name")).append("\r\n")
27-
.append("更新内容: \r\n").append(features)
28-
.toString();
29-
if (FxAlerts.confirmOkCancel("发现新版本 " + latestVersion, content)) {
30-
try {
20+
try {
21+
String json = HttpUtil.get("https://gitee.com/api/v5/repos/xwintop/xJavaFxTool/releases/latest");
22+
JSONObject node = JSON.parseObject(json);
23+
final String latestVersion = node.getString("tag_name");
24+
final String features = node.getString("body");
25+
if (isLargerThanCurrent(latestVersion)) {
26+
final String content = new StringBuilder()
27+
.append("版本名:").append(node.getString("name")).append("\r\n")
28+
.append("更新内容: \r\n").append(features)
29+
.toString();
30+
if (FxAlerts.confirmOkCancel("发现新版本 " + latestVersion, content)) {
3131
HttpClientUtil.openBrowseURLThrowsException("https://gitee.com/xwintop/xJavaFxTool/releases");
32-
} catch (Exception e) {
33-
log.error("打开新版本地址失败!", e);
3432
}
3533
}
34+
} catch (Exception e) {
35+
log.error("检查新版本失败!", e);
3636
}
3737
}
3838

0 commit comments

Comments
 (0)