Skip to content

Commit 497ff9a

Browse files
committed
1.添加新版本检查
1 parent a420a35 commit 497ff9a

4 files changed

Lines changed: 79 additions & 5 deletions

File tree

src/main/java/com/xwintop/xJavaFxTool/XJavaFxToolApplication.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.xwintop.xJavaFxTool.utils.Config;
55
import com.xwintop.xJavaFxTool.utils.Config.Keys;
66
import com.xwintop.xJavaFxTool.utils.StageUtils;
7+
import com.xwintop.xJavaFxTool.utils.VersionChecker;
78
import com.xwintop.xcore.javafx.FxApp;
89
import com.xwintop.xcore.javafx.dialog.FxAlerts;
910
import javafx.application.Application;
@@ -54,6 +55,9 @@ public void start(Stage primaryStage) throws Exception {
5455
loadClassicUI(primaryStage);
5556

5657
StageUtils.loadPrimaryStageBound(primaryStage);
58+
primaryStage.setOnShown(windowEvent -> {
59+
VersionChecker.checkNewVersion();
60+
});
5761
primaryStage.show();
5862
}
5963

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package com.xwintop.xJavaFxTool.services;
22

33
import com.xwintop.xJavaFxTool.AppException;
4+
import com.xwintop.xJavaFxTool.XJavaFxToolApplication;
45
import com.xwintop.xJavaFxTool.common.logback.ConsoleLogAppender;
56
import com.xwintop.xJavaFxTool.controller.IndexController;
67
import com.xwintop.xJavaFxTool.model.PluginJarInfo;
78
import com.xwintop.xJavaFxTool.plugin.PluginClassLoader;
89
import com.xwintop.xJavaFxTool.plugin.PluginContainer;
910
import com.xwintop.xJavaFxTool.utils.Config;
11+
import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil;
1012
import com.xwintop.xcore.javafx.dialog.FxAlerts;
1113
import com.xwintop.xcore.util.javafx.AlertUtil;
1214
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
15+
import javafx.application.Platform;
1316
import javafx.event.ActionEvent;
1417
import javafx.event.Event;
1518
import javafx.fxml.FXMLLoader;
@@ -49,6 +52,15 @@ public void setLanguageAction(String languageType) throws Exception {
4952
Config.set(Config.Keys.Locale, Locale.US);
5053
}
5154
AlertUtil.showInfoAlert(indexController.getBundle().getString("SetLanguageText"));
55+
XJavaFxToolApplication.getStage().close();
56+
Platform.runLater(() -> {
57+
try {
58+
XJavaFxSystemUtil.initSystemLocal(); // 初始化本地语言
59+
new XJavaFxToolApplication().start(new Stage());
60+
} catch (Exception e) {
61+
e.printStackTrace();
62+
}
63+
});
5264
}
5365

5466
public void addNodepadAction(ActionEvent event) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
@Setter
2727
@Slf4j
2828
public class PluginManageService {
29-
30-
public static final String PLUGIN_LIST_URL = "https://xwintop.gitee.io/maven/plugin-libs/plugin-list.json";
31-
32-
public static final String PLUGIN_LIST_PATH = "system_plugin_list.json";
33-
3429
private PluginManageController pluginManageController;
3530

3631
private PluginManager pluginManager = PluginManager.getInstance();
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.xwintop.xJavaFxTool.utils;
2+
3+
import cn.hutool.http.HttpUtil;
4+
import com.alibaba.fastjson.JSON;
5+
import com.alibaba.fastjson.JSONObject;
6+
import com.xwintop.xcore.javafx.dialog.FxAlerts;
7+
import com.xwintop.xcore.util.HttpClientUtil;
8+
import lombok.extern.slf4j.Slf4j;
9+
10+
/**
11+
* @ClassName: VersionChecker
12+
* @Description: 新版本检查
13+
* @author: xufeng
14+
* @date: 2022/3/28 14:59
15+
*/
16+
17+
@Slf4j
18+
public class VersionChecker {
19+
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 {
31+
HttpClientUtil.openBrowseURLThrowsException("https://gitee.com/xwintop/xJavaFxTool/releases");
32+
} catch (Exception e) {
33+
log.error("打开新版本地址失败!", e);
34+
}
35+
}
36+
}
37+
}
38+
39+
private static Boolean isLargerThanCurrent(String remoteVersion) {
40+
final String[] arr = remoteVersion.split("v");
41+
String r = remoteVersion;
42+
if (arr.length == 2) {
43+
r = arr[1];
44+
}
45+
46+
final String[] localVersionArr = Config.xJavaFxToolVersions.substring(1).split("\\.");
47+
final String[] remoteVersionArr = r.split("\\.");
48+
for (int i = 0; i < localVersionArr.length; i++) {
49+
try {
50+
final int localVersionSymbol = Integer.parseInt(localVersionArr[i]);
51+
final int remoteVersionSymbol = Integer.parseInt(remoteVersionArr[i]);
52+
if (localVersionSymbol < remoteVersionSymbol) {
53+
return true;
54+
} else if (localVersionSymbol > remoteVersionSymbol) {
55+
return false;
56+
}
57+
} catch (Exception e) {
58+
return true;
59+
}
60+
}
61+
return false;
62+
}
63+
}

0 commit comments

Comments
 (0)