33import com .xwintop .xJavaFxTool .Main ;
44import com .xwintop .xJavaFxTool .controller .IndexController ;
55import com .xwintop .xJavaFxTool .controller .index .PluginManageController ;
6+ import com .xwintop .xJavaFxTool .event .AppEvents ;
7+ import com .xwintop .xJavaFxTool .event .PluginEvent ;
68import com .xwintop .xJavaFxTool .model .PluginJarInfo ;
79import com .xwintop .xJavaFxTool .newui .creator .CreatePluginProjectService ;
810import com .xwintop .xJavaFxTool .newui .creator .PluginProjectInfo ;
911import com .xwintop .xJavaFxTool .plugin .PluginManager ;
12+ import com .xwintop .xJavaFxTool .plugin .PluginParser ;
1013import com .xwintop .xJavaFxTool .services .index .SystemSettingService ;
1114import com .xwintop .xcore .javafx .FxApp ;
1215import com .xwintop .xcore .javafx .dialog .FxAlerts ;
1316import com .xwintop .xcore .javafx .dialog .FxDialog ;
1417import com .xwintop .xcore .util .javafx .JavaFxViewUtil ;
15- import java .awt .Desktop ;
16- import java .io .File ;
17- import java .io .IOException ;
18- import java .net .URI ;
19- import java .util .ArrayList ;
20- import java .util .HashMap ;
21- import java .util .List ;
22- import java .util .Map ;
23- import java .util .ResourceBundle ;
2418import javafx .beans .Observable ;
2519import javafx .fxml .FXMLLoader ;
2620import javafx .scene .Parent ;
27- import javafx .scene .control .ButtonType ;
28- import javafx .scene .control .CheckMenuItem ;
29- import javafx .scene .control .ContextMenu ;
30- import javafx .scene .control .Hyperlink ;
31- import javafx .scene .control .TabPane ;
3221import javafx .scene .control .TextField ;
22+ import javafx .scene .control .*;
3323import javafx .scene .layout .VBox ;
3424import javafx .scene .web .WebView ;
3525import lombok .extern .slf4j .Slf4j ;
3626import org .apache .commons .lang3 .StringUtils ;
3727
28+ import java .awt .*;
29+ import java .io .File ;
30+ import java .io .IOException ;
31+ import java .net .URI ;
32+ import java .util .ArrayList ;
33+ import java .util .HashMap ;
34+ import java .util .List ;
35+ import java .util .Map ;
36+
3837@ Slf4j
3938public class NewLauncherController {
4039
@@ -55,12 +54,22 @@ public class NewLauncherController {
5554 // 实现搜索用
5655 private final List <PluginItemController > pluginItemControllers = new ArrayList <>();
5756
57+ private final Map <String , PluginCategoryController > categoryControllers = new HashMap <>();
58+
5859 public void initialize () {
5960 NewLauncherService .getInstance ().setController (this );
6061 txtSearch .textProperty ().addListener (this ::onSearchKeywordChanged );
62+
6163 initContextMenu ();
6264 loadPlugins (); // 加载插件列表到界面上
65+
6366 startWebView .getEngine ().load (IndexController .QQ_URL ); // 额外再打开一个反馈页面,可关闭
67+
68+ AppEvents .addEventHandler (PluginEvent .PLUGIN_DOWNLOADED , pluginEvent -> {
69+ PluginJarInfo pluginJarInfo = pluginEvent .getPluginJarInfo ();
70+ PluginParser .parse (pluginJarInfo .getFile (), pluginJarInfo );
71+ loadPlugins ();
72+ });
6473 }
6574
6675 private void initContextMenu () {
@@ -101,35 +110,34 @@ private void loadPlugins() {
101110
102111 this .pluginCategories .getChildren ().clear ();
103112 this .pluginItemControllers .clear ();
113+ this .categoryControllers .clear ();
104114
105115 List <PluginJarInfo > pluginList = PluginManager .getInstance ().getPluginList ();
106- ResourceBundle menuResourceBundle = Main .RESOURCE_BUNDLE ;
107-
108- Map <String , PluginCategoryController > categoryControllers = new HashMap <>();
116+ pluginList .forEach (this ::loadPlugin );
117+ }
109118
110- for (PluginJarInfo jarInfo : pluginList ) {
111- String menuParentTitle = jarInfo .getMenuParentTitle ();
112- if (menuParentTitle != null ) {
119+ public void loadPlugin (PluginJarInfo jarInfo ) {
120+ String menuParentTitle = jarInfo .getMenuParentTitle ();
121+ if (menuParentTitle != null ) {
113122
114- String categoryName = jarInfo .getIsFavorite () ?
115- FAVORITE_CATEGORY_NAME : menuResourceBundle .getString (menuParentTitle );
123+ String categoryName = jarInfo .getIsFavorite () ?
124+ FAVORITE_CATEGORY_NAME : Main . RESOURCE_BUNDLE .getString (menuParentTitle );
116125
117- PluginCategoryController category = categoryControllers .computeIfAbsent (
118- categoryName , __ -> {
119- PluginCategoryController _category =
120- PluginCategoryController .newInstance (categoryName );
121- addCategory (_category );
122- return _category ;
123- }
124- );
126+ PluginCategoryController category = categoryControllers .computeIfAbsent (
127+ categoryName , __ -> {
128+ PluginCategoryController _category =
129+ PluginCategoryController .newInstance (categoryName );
130+ addCategory (_category );
131+ return _category ;
132+ }
133+ );
125134
126- PluginItemController item = PluginItemController .newInstance (jarInfo );
127- item .setContextMenu (itemContextMenu );
128- category .addItem (item );
135+ PluginItemController item = PluginItemController .newInstance (jarInfo );
136+ item .setContextMenu (itemContextMenu );
137+ category .addItem (item );
129138
130- if (!pluginItemControllers .contains (item )) {
131- pluginItemControllers .add (item );
132- }
139+ if (!pluginItemControllers .contains (item )) {
140+ pluginItemControllers .add (item );
133141 }
134142 }
135143 }
0 commit comments