2121import javafx .fxml .FXMLLoader ;
2222import javafx .scene .control .*;
2323import javafx .stage .FileChooser .ExtensionFilter ;
24- import javafx .stage .Window ;
2524import javafx .util .Callback ;
2625import lombok .Getter ;
2726import lombok .Setter ;
2827import lombok .extern .slf4j .Slf4j ;
28+ import org .apache .commons .io .FileUtils ;
2929
3030import java .io .File ;
3131import 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