Skip to content

Commit

Permalink
Bug fixes and improvements
Browse files Browse the repository at this point in the history
汉化
  • Loading branch information
RedDragon0293 committed Jun 4, 2024
1 parent f480642 commit d649d56
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 46 deletions.
5 changes: 4 additions & 1 deletion src/main/java/cn/reddragon/eportal/EPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public class EPortal extends Application {
//System.out.println("Heartbeat.");
Authenticator.updateStatus();
Platform.runLater(controller::updateUI);
Thread.sleep(5000L);
if (Authenticator.error)
Thread.sleep(1000L);
else
Thread.sleep(5000L);
} catch (Exception e) {
//throw new RuntimeException(e);
e.printStackTrace();
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/cn/reddragon/eportal/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class MainController {

public void updateUI() {
StringBuilder sb = new StringBuilder();
sb.append("Status: ");
sb.append("状态: ");
if (Authenticator.online) {
sb.append("Online ");
sb.append("在线 ");
if (Authenticator.type == null) {
sb.append("(...)");
} else
Expand All @@ -53,27 +53,27 @@ public void updateUI() {
}
}
} else {
sb.append("Offline");
sb.append("离线");
}
if (Platform.isFxApplicationThread()) {
statusLabel.setText(sb.toString());
button.setDisable(Authenticator.error);
if (Authenticator.online)
button.setText("Logout");
button.setText("登出");
else {
button.setText("Login");
user.setText("User: null");
remainLabel.setText("Time remaining:");
button.setText("登录");
user.setText("当前用户: null");
remainLabel.setText("剩余时长:");
}
} else Platform.runLater(() -> {
statusLabel.setText(sb.toString());
button.setDisable(Authenticator.error);
if (Authenticator.online)
button.setText("Logout");
button.setText("登出");
else {
button.setText("Login");
user.setText("User: null");
remainLabel.setText("Time remaining:");
button.setText("登录");
user.setText("当前用户: null");
remainLabel.setText("剩余时长:");
}
});
}
Expand All @@ -82,10 +82,10 @@ public void updateUI() {
public void onLoginButtonClick() {
button.setDisable(true);
if (Authenticator.online) {
if (button.getText().equals("Login")) {
resultText.setText("Already logged in!");
button.setText("Logout");
} else if (button.getText().equals("Logout")) {
if (button.getText().equals("登录")) {
resultText.setText("当前设备已登录!");
button.setText("登出");
} else if (button.getText().equals("登出")) {
new Thread(() -> {
HttpURLConnection connection = null;
try {
Expand Down Expand Up @@ -119,12 +119,12 @@ public void onLoginButtonClick() {
}
String username = userNameField.getText();
if (username.isBlank()) {
resultText.setText("Please enter your username!");
resultText.setText("请输入用户名!");
return;
}
String password = passwordField.getText();
if (password.isBlank()) {
resultText.setText("Please enter your password!");
resultText.setText("请输入密码!");
return;
}
String userId = URIEncoder.encodeURI(URIEncoder.encodeURI(username));
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/cn/reddragon/eportal/utils/Authenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static void checkOnline() {
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_MOVED_TEMP) {
if (EPortal.controller != null) {
Platform.runLater(() -> EPortal.controller.resultText.setText("Error: Auth server error!"));
Platform.runLater(() -> EPortal.controller.resultText.setText("错误: 与认证服务器通信时出错!"));
error = true;
}
return;
Expand All @@ -122,14 +122,14 @@ public static void checkOnline() {
} catch (SocketTimeoutException e) {
System.err.println(e.getMessage());
if (EPortal.controller != null) {
Platform.runLater(() -> EPortal.controller.resultText.setText("Error: Auth server connection timeout!"));
Platform.runLater(() -> EPortal.controller.resultText.setText("错误: 无法连接到认证服务器!"));
error = true;
}
online = false;
} catch (SocketException e) {
System.err.println(e.getMessage());
if (EPortal.controller != null) {
Platform.runLater(() -> EPortal.controller.resultText.setText("Error: No Internet connection!"));
Platform.runLater(() -> EPortal.controller.resultText.setText("错误: 无网络连接!"));
error = true;
}
online = false;
Expand Down Expand Up @@ -181,7 +181,7 @@ private static String updateSessionInternal() {
String r = resultJson.get("result").getAsString();
if (Objects.equals(r, "success")) {
// 设置当前用户
Platform.runLater(() -> EPortal.controller.user.setText("User: " + resultJson.get("userName").getAsString() + " (" + resultJson.get("userId").getAsString() + ")"));
Platform.runLater(() -> EPortal.controller.user.setText("当前用户: " + resultJson.get("userName").getAsString() + " (" + resultJson.get("userId").getAsString() + ")"));
// 设置运营商、剩余时间
JsonArray ballArray = JsonParser.parseString(resultJson.get("ballInfo").getAsString()).getAsJsonArray();
if (ballArray.get(1).getAsJsonObject().get("displayName").getAsString().equals("我的运营商")) {
Expand All @@ -190,13 +190,13 @@ private static String updateSessionInternal() {
Authenticator.type = it;
}
}
Platform.runLater(() -> EPortal.controller.remainLabel.setText("Time remaining: ∞"));
Platform.runLater(() -> EPortal.controller.remainLabel.setText("剩余时长: ∞"));
return r;
}
Authenticator.type = LoginType.WAN;
int duration = ballArray.get(1).getAsJsonObject().get("value").getAsInt();
StringBuilder sb = new StringBuilder();
sb.append("Time remaining: ");
sb.append("剩余时长: ");
//计算剩余时间
int h = duration / 3600;
int m = (duration % 3600) / 60;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/reddragon/eportal/utils/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class HttpUtils {
public static HttpURLConnection make(String url, String mode) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod(mode);
connection.setConnectTimeout(1000);
connection.setReadTimeout(1000);
connection.setConnectTimeout(500);
connection.setReadTimeout(500);
connection.setDoOutput(true);
connection.setRequestProperty("User-Agent", DEFAULT_AGENT);
return connection;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/cn/reddragon/eportal/utils/LoginType.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cn.reddragon.eportal.utils;

public enum LoginType {
WAN("校园外网服务(out-campus NET)", "CampusNet"),
CHINAMOBILE("中国移动(CMCC NET)", "ChinaMobile"),
CHINATELECOM("中国电信(常州)", "ChinaTelecom"),
CHINAUNICOM("中国联通(常州)", "ChinaUnicom");
WAN("校园外网服务(out-campus NET)", "校园网"),
CHINAMOBILE("中国移动(CMCC NET)", "中国移动"),
CHINATELECOM("中国电信(常州)", "中国电信(常州)"),
CHINAUNICOM("中国联通(常州)", "中国联通(常州)");
public final String authName, displayName;

LoginType(String authName, String displayName) {
Expand Down
27 changes: 11 additions & 16 deletions src/main/resources/cn/reddragon/eportal/hello-view.fxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>


<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.VBox?>
Expand All @@ -9,19 +8,15 @@
<children>
<MenuBar maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<Menu mnemonicParsing="false" text="设置">
<items>
<MenuItem mnemonicParsing="false" text="Delete"/>
<CheckMenuItem mnemonicParsing="false" text="自动重连"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<Menu mnemonicParsing="false" text="帮助">
<items>
<MenuItem mnemonicParsing="false" text="About"/>
<MenuItem mnemonicParsing="false" text="日志"/>
<MenuItem mnemonicParsing="false" text="关于"/>
</items>
</Menu>
</menus>
Expand All @@ -30,13 +25,13 @@
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
</padding>
<Label fx:id="statusLabel" text="Status:"/>
<Label fx:id="user" text="User: null"/>
<Label fx:id="remainLabel" text="Time remaining: No user logon"/>
<TextField fx:id="userNameField" promptText="Username"/>
<PasswordField fx:id="passwordField" promptText="Password"/>
<Label fx:id="statusLabel" text="状态:"/>
<Label fx:id="user" text="当前用户: null"/>
<Label fx:id="remainLabel" text="剩余时长: 未登录"/>
<TextField fx:id="userNameField" promptText="用户名"/>
<PasswordField fx:id="passwordField" promptText="密码"/>
<ChoiceBox fx:id="selector" prefWidth="150.0"/>
<Button fx:id="button" onAction="#onLoginButtonClick" text="Login"/>
<Button fx:id="button" onAction="#onLoginButtonClick" text="登录"/>

<Label fx:id="resultText" textAlignment="CENTER"/>
</VBox>
Expand Down

0 comments on commit d649d56

Please sign in to comment.