From e296a9be1882248e7191fedb31b86b2207e349ba Mon Sep 17 00:00:00 2001 From: RedDragon0293 <1352003034@qq.com> Date: Sat, 27 Apr 2024 08:29:36 +0800 Subject: [PATCH] Bug fixes and improvements --- .../cn/reddragon/eportal/HelloController.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/cn/reddragon/eportal/HelloController.java b/src/main/java/cn/reddragon/eportal/HelloController.java index 065a98c..b0d1eeb 100644 --- a/src/main/java/cn/reddragon/eportal/HelloController.java +++ b/src/main/java/cn/reddragon/eportal/HelloController.java @@ -47,14 +47,14 @@ public void updateUI() { if (Authenticator.type == null) { sb.append("(...)"); } else - for (LoginType it : LoginType.values()) { - if (Objects.equals(it, Authenticator.type)) { - sb.append('('); - sb.append(it.displayName); - sb.append(')'); - break; + for (LoginType it : LoginType.values()) { + if (Objects.equals(it, Authenticator.type)) { + sb.append('('); + sb.append(it.displayName); + sb.append(')'); + break; + } } - } } else { button.setText("Login"); sb.append("Offline"); @@ -73,8 +73,9 @@ protected void onLoginButtonClick() { button.setText("Logout"); } else if (button.getText().equals("Logout")) { new Thread(() -> { + HttpURLConnection connection = null; try { - HttpURLConnection connection = Authenticator.logout(); + connection = Authenticator.logout(); if (connection == null) { Platform.runLater(() -> { resultText.setText("Error!"); @@ -90,6 +91,10 @@ protected void onLoginButtonClick() { } catch (Exception e) { e.printStackTrace(); Platform.runLater(() -> resultText.setText(e.getMessage())); + } finally { + if (connection != null) { + connection.disconnect(); + } } Platform.runLater(() -> button.setDisable(false)); }).start();