Skip to content

Commit 1f2e71d

Browse files
committed
1.移除多余方法
1 parent f826c37 commit 1f2e71d

4 files changed

Lines changed: 10 additions & 31 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,10 @@ public static FXMLLoader getFXMLLoader() {
7373
@Override
7474
public void initialize(URL location, ResourceBundle resources) {
7575
this.bundle = resources;
76-
7776
initView();
7877
initEvent();
7978
initService();
8079
initNotepad();
81-
82-
this.indexService.addWebView(XJavaFxToolApplication.RESOURCE_BUNDLE.getString("feedback"), QQ_URL, null);
83-
this.tongjiWebView.getEngine().load(STATISTICS_URL);
84-
this.tabPaneMain.getSelectionModel().select(0);
8580
}
8681

8782
private void initNotepad() {
@@ -91,6 +86,9 @@ private void initNotepad() {
9186
}
9287

9388
private void initView() {
89+
this.indexService.addWebView(XJavaFxToolApplication.RESOURCE_BUNDLE.getString("feedback"), QQ_URL, null);
90+
this.tongjiWebView.getEngine().load(STATISTICS_URL);
91+
this.tabPaneMain.getSelectionModel().select(0);
9492
}
9593

9694
private void initEvent() {

src/main/java/com/xwintop/xJavaFxTool/plugin/PluginManager.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,17 @@ public class PluginManager {
5151

5252
public static PluginManager getInstance() {
5353
if (instance == null) {
54-
instance = new PluginManager(LOCAL_PLUGINS_PATH);
54+
instance = new PluginManager();
5555
}
5656
return instance;
5757
}
5858

5959
//////////////////////////////////////////////////////////////
60-
61-
private final String localPluginsPath;
62-
6360
private final OkHttpClient pluginDownloader = new OkHttpClient.Builder().addInterceptor(new DownloadProgressInterceptor()).build();
6461

6562
private final List<PluginJarInfo> pluginList = new ArrayList<>(); // 插件列表
6663

67-
public PluginManager(String localPluginsPath) {
68-
this.localPluginsPath = localPluginsPath;
64+
public PluginManager() {
6965
this.loadLocalPluginConfiguration();
7066
}
7167

@@ -98,7 +94,7 @@ public PluginJarInfo getPluginByFxmlPath(String fxmlPath) {
9894
*/
9995
private void loadLocalPluginConfiguration() {
10096
try {
101-
Path path = Paths.get(this.localPluginsPath);
97+
Path path = Paths.get(LOCAL_PLUGINS_PATH);
10298
if (!Files.exists(path)) {
10399
return;
104100
}
@@ -275,7 +271,7 @@ private void tryDownload(String pluginName, String url, String ua, File file) th
275271
// 保存配置,如果失败则抛出异常
276272
public void saveToFile() throws IOException {
277273
String json = JSON.toJSONString(this.pluginList, true);
278-
Path path = Paths.get(this.localPluginsPath);
274+
Path path = Paths.get(LOCAL_PLUGINS_PATH);
279275
if (!Files.exists(path)) {
280276
Files.createFile(path);
281277
}

src/main/java/com/xwintop/xJavaFxTool/plugin/PluginParser.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,16 @@ public static void parse(File pluginFile, PluginJarInfo pluginJarInfo) {
4242
* 解析插件文件,补完 pluginJarInfo 属性
4343
*/
4444
public static void parse(File pluginFile, PluginJarInfo pluginJarInfo, ClassLoader classLoader) {
45-
4645
if (!pluginFile.exists()) {
4746
log.error("插件 {} 文件不存在: {}", pluginJarInfo.getName(), pluginFile.getAbsolutePath());
4847
return;
4948
}
5049

5150
try (JarFile jarFile = new JarFile(pluginFile)) {
52-
5351
JarEntry entry = jarFile.getJarEntry(ENTRY_NAME);
5452
if (entry == null) {
5553
return;
5654
}
57-
5855
Element root = createRootElement(jarFile, entry);
5956
List<Element> menuElements = selectElements(root, "/root/ToolFxmlLoaderConfiguration[@isMenu='true']");
6057
Element pluginElement = selectSingleElement(root, "/root/ToolFxmlLoaderConfiguration[not(@isMenu)]");
@@ -84,7 +81,6 @@ public static void parse(File pluginFile, PluginJarInfo pluginJarInfo, ClassLoad
8481
}
8582

8683
pluginJarInfo.setName(StringUtils.defaultString(pluginJarInfo.getName(), title));
87-
8884
} catch (IOException | DocumentException e) {
8985
throw new AppException(e);
9086
}

src/main/java/com/xwintop/xJavaFxTool/services/IndexService.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import lombok.extern.slf4j.Slf4j;
2828
import org.apache.commons.lang3.StringUtils;
2929

30-
import java.lang.ref.WeakReference;
3130
import java.util.HashMap;
3231
import java.util.Locale;
3332
import java.util.Map;
@@ -131,7 +130,6 @@ public void loadPlugin(PluginJarInfo pluginJarInfo) {
131130
public static Tab loadIsolatedPluginAsTab(PluginJarInfo plugin, TabPane tabPane, boolean singleWindowBoot) {
132131
try {
133132
PluginContainer pluginContainer = new PluginContainer(PluginClassLoader.class.getClassLoader(), plugin);
134-
WeakReference<PluginContainer> containerRef = new WeakReference<>(pluginContainer);
135133
FXMLLoader generatingCodeFXMLLoader = pluginContainer.createFXMLLoader();
136134
if (generatingCodeFXMLLoader == null) {
137135
return null;
@@ -151,25 +149,16 @@ public static Tab loadIsolatedPluginAsTab(PluginJarInfo plugin, TabPane tabPane,
151149
}
152150

153151
Node root = generatingCodeFXMLLoader.load();
154-
Object controller = generatingCodeFXMLLoader.getController();
155-
WeakReference<Object> controllerRef = new WeakReference<>(controller);
156152

157153
tab.setContent(root);
158154
tabPane.getTabs().add(tab);
159155
tabPane.getSelectionModel().select(tab);
160156

161157
tab.setOnCloseRequest(
162158
event -> {
163-
Object ctrl = controllerRef.get();
164-
if (ctrl != null) {
165-
JavaFxViewUtil.setControllerOnCloseRequest(ctrl, event);
166-
}
167-
168-
PluginContainer container = containerRef.get();
169-
if (container != null) {
170-
log.info("插件关闭:" + container.getPluginJarInfo().getName());
171-
container.unload();
172-
}
159+
JavaFxViewUtil.setControllerOnCloseRequest(generatingCodeFXMLLoader.getController(), event);
160+
log.info("插件关闭:" + pluginContainer.getPluginJarInfo().getName());
161+
pluginContainer.unload();
173162
}
174163
);
175164

0 commit comments

Comments
 (0)