Skip to content

Commit 44fc416

Browse files
committed
1.添加下载插件时删除老版插件包方法;2.优化插件信息记录方式
1 parent 09d488e commit 44fc416

7 files changed

Lines changed: 208 additions & 267 deletions

File tree

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,8 @@ private void addMenu(PluginJarInfo jarInfo) {
169169
moreToolsMenu.getItems().add(menu);
170170
}
171171
MenuItem menuItem = new MenuItem(jarInfo.getTitle());
172-
if (jarInfo.getIconImage() == null) {
173-
if (StringUtils.isNotEmpty(jarInfo.getIconPath())) {
174-
ImageView imageView = new ImageView(new Image(jarInfo.getIconPath()));
175-
imageView.setFitHeight(18);
176-
imageView.setFitWidth(18);
177-
menuItem.setGraphic(imageView);
178-
}
179-
} else {
180-
ImageView imageView = new ImageView(jarInfo.getIconImage());
172+
if (jarInfo.getIconImage() != null || StringUtils.isNotEmpty(jarInfo.getIconPath())) {
173+
ImageView imageView = new ImageView(jarInfo.getIconImage() == null ? new Image(jarInfo.getIconPath()) : jarInfo.getIconImage());
181174
imageView.setFitHeight(18);
182175
imageView.setFitWidth(18);
183176
menuItem.setGraphic(imageView);

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import javafx.fxml.FXMLLoader;
2222
import javafx.scene.control.*;
2323
import javafx.stage.FileChooser.ExtensionFilter;
24-
import javafx.stage.Window;
2524
import javafx.util.Callback;
2625
import lombok.Getter;
2726
import lombok.Setter;
2827
import lombok.extern.slf4j.Slf4j;
28+
import org.apache.commons.io.FileUtils;
2929

3030
import java.io.File;
3131
import java.io.IOException;
@@ -63,10 +63,6 @@ public void initialize(URL location, ResourceBundle resources) {
6363
initService();
6464
}
6565

66-
public Window getWindow() {
67-
return this.pluginDataTableView.getScene().getWindow();
68-
}
69-
7066
private void initView() {
7167
addLocalPluginButton.setVisible(Boolean.parseBoolean(System.getProperty("localPluginEnabled", "false")));
7268

@@ -95,7 +91,7 @@ protected void updateItem(String item, boolean empty) {
9591
downloadButton.setDisable(true);
9692
}
9793
this.setContentDisplay(ContentDisplay.CENTER);
98-
downloadButton.setOnMouseClicked(event -> downloadPlugin(dataRow, downloadButton));
94+
downloadButton.setOnMouseClicked(event -> downloadPlugin(dataRow));
9995
this.setGraphic(downloadButton);
10096
}
10197
}
@@ -106,36 +102,37 @@ protected void updateItem(String item, boolean empty) {
106102
pluginDataTableView.setItems(pluginDataTableData);
107103
}
108104

109-
private void downloadPlugin(Map<String, String> dataRow, Button downloadButton) {
105+
private void downloadPlugin(Map<String, String> dataRow) {
110106
try {
111107
pluginManageService.downloadPluginJar(dataRow, pluginJarInfo ->
112-
Platform.runLater(() -> afterDownload(dataRow, downloadButton, pluginJarInfo))
108+
Platform.runLater(() -> afterDownload(dataRow, pluginJarInfo))
113109
);
114110
} catch (Exception e) {
115111
log.error("下载插件失败:", e);
116112
TooltipUtil.showToast("下载插件失败:" + e.getMessage());
117113
}
118114
}
119115

120-
private void afterDownload(Map<String, String> dataRow, Button downloadButton, PluginJarInfo pluginJarInfo) {
116+
private void afterDownload(Map<String, String> dataRow, PluginJarInfo pluginJarInfo) {
121117
// 没有下载成功不做处理
122118
if (pluginJarInfo.getIsDownload() == null || !pluginJarInfo.getIsDownload()) {
123119
return;
124120
}
125-
126121
try {
122+
PluginJarInfo pluginJarInfoOld = PluginManager.getInstance().getPlugin(pluginJarInfo.getJarName());
123+
if (pluginJarInfoOld != null) {
124+
FileUtils.delete(pluginJarInfoOld.getFile());
125+
}
126+
PluginManager.getInstance().getPluginList().remove(pluginJarInfoOld);
127+
PluginManager.getInstance().getPluginList().add(pluginJarInfo);
127128
PluginManager.getInstance().saveToFile();
128129
TooltipUtil.showToast("插件 " + dataRow.get("nameTableColumn") + " 下载完成");
129-
130130
PluginClassLoader tempClassLoader = PluginClassLoader.create(pluginJarInfo.getFile());
131131
PluginParser.parse(pluginJarInfo.getFile(), pluginJarInfo, tempClassLoader);
132132

133133
dataRow.put("isEnableTableColumn", "true");
134134
dataRow.put("isDownloadTableColumn", "已下载");
135135

136-
downloadButton.setText("已下载");
137-
downloadButton.setDisable(true);
138-
139136
pluginDataTableView.refresh();
140137
AppEvents.fire(new PluginEvent(PluginEvent.PLUGIN_DOWNLOADED, pluginJarInfo));
141138
} catch (IOException e) {
@@ -147,15 +144,15 @@ private void afterDownload(Map<String, String> dataRow, Button downloadButton, P
147144
private void initEvent() {
148145
// 右键菜单
149146
ContextMenu contextMenu = new ContextMenu();
150-
JavaFxViewUtil.addMenuItem(contextMenu,"保存配置", actionEvent -> {
147+
JavaFxViewUtil.addMenuItem(contextMenu, "保存配置", actionEvent -> {
151148
try {
152149
PluginManager.getInstance().saveToFile();
153150
TooltipUtil.showToast("保存配置成功");
154151
} catch (Exception ex) {
155152
log.error("保存插件配置失败", ex);
156153
}
157154
});
158-
JavaFxViewUtil.addMenuItem(contextMenu,"删除插件", actionEvent -> {
155+
JavaFxViewUtil.addMenuItem(contextMenu, "删除插件", actionEvent -> {
159156
pluginManageService.deletePlugin();
160157
});
161158
pluginDataTableView.setContextMenu(contextMenu);

0 commit comments

Comments
 (0)