Skip to content

Commit

Permalink
Updater
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Dec 29, 2017
1 parent 729e727 commit f195f78
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/me/kevinwalker/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void start(Stage primaryStage) throws Exception {
mainGui.getStage().show();
load("MainPage", "主界面", new Image(ZipUtils.getInputStream(new File(Util.getBaseDir(), Config.instance.skin), "MainPage.png")), true);
load("Settings", "设置", new Image(ZipUtils.getInputStream(new File(Util.getBaseDir(), Config.instance.skin), "Settings.png")), false);
load("ResourceManagement", "资源管理", new Image(ZipUtils.getInputStream(new File(Util.getBaseDir(), Config.instance.skin), "ResourceManagement.png")), false);
load("ResourceManagement", "服务器信息", new Image(ZipUtils.getInputStream(new File(Util.getBaseDir(), Config.instance.skin), "ServerInformation.png")), false);
load("ResourceManagement", "资源管理", new Image(ZipUtils.getInputStream(new File(Util.getBaseDir(), Config.instance.skin), "resourceManagementImg.png")), false);
load("ResourceManagement", "服务器信息", new Image(ZipUtils.getInputStream(new File(Util.getBaseDir(), Config.instance.skin), "serverInformationImg.png")), false);
load("Skin", "启动器皮肤", new Image(ZipUtils.getInputStream(new File(Util.getBaseDir(), Config.instance.skin), "Skin.png")), false);
load("Resources", "资源获取", new Image(ZipUtils.getInputStream(new File(Util.getBaseDir(), Config.instance.skin), "loginImg.png")), false);
/*
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/me/kevinwalker/ui/controller/SettingsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,38 @@
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import javafx.application.Platform;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import me.kevinwalker.main.Apis;
import me.kevinwalker.main.Config;
import me.kevinwalker.utils.io.Updater;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SettingsController implements Initializable {
private static ExecutorService service = Executors.newFixedThreadPool(1);

public Button enableProxy;
public VBox proxySettingBox, settingPane;
public TextField proxyHost;
public TextField proxyPort;
public TextField proxyUser;
public TextField proxyPassword;
public Button checkUpdate;
public Text versionInfo;

public static void main(String[] args) {
try {
Expand Down Expand Up @@ -75,6 +84,11 @@ public void initialize(URL location, ResourceBundle resources) {
Config.instance.enableProxy = false;
}
});
versionInfo.setText("当前版本 " + Updater.currentVersion() + "/" + Updater.currentCommit());
checkUpdate.setOnMouseClicked((MouseEvent event) -> service.execute(() -> {
String v = Updater.checkUpdate();
Platform.runLater(() -> versionInfo.setText("最新版本 " + v));
}));
}

}
52 changes: 52 additions & 0 deletions src/main/java/me/kevinwalker/utils/io/Updater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package me.kevinwalker.utils.io;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;

public class Updater {

private static String version, commit;


static {
JsonObject object = new JsonParser().parse(new InputStreamReader(
Updater.class.getResourceAsStream("/version.json"))).getAsJsonObject();
version = object.get("current").getAsString();
commit = object.get("commit").getAsString();
}

public static String newVersion = version, newCommit = commit;

public static String currentVersion() {
return version;
}

public static String currentCommit() {
return commit;
}

public static String checkUpdate() {
try {
URL url = new URL("https://api.github.com/repos/IzzelAliz/LCL/releases/latest");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
JsonObject object = new JsonParser().parse(reader.readLine()).getAsJsonObject();
newVersion = object.get("tag_name").getAsString();
newCommit = object.get("body").getAsString();
return newVersion + "/" + newCommit;
} catch (IOException e) {
e.printStackTrace();
}
return "";
}

}
2 changes: 2 additions & 0 deletions src/main/resources/fxml/Settings.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
</HBox>
</children>
</VBox>
<Button fx:id="checkUpdate" mnemonicParsing="false" text="检查更新" textFill="WHITE" />
<Text fx:id="versionInfo" fill="WHITE" strokeType="OUTSIDE" strokeWidth="0.0" text="当前版本" />
</children>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"version": "1.0"
"current": "11",
"commit": "000000000000000"
}

0 comments on commit f195f78

Please sign in to comment.