diff --git a/src/main/java/top/octopusyan/config/ProxyConfig.java b/src/main/java/top/octopusyan/config/ProxyConfig.java index 43c970e..80ced07 100644 --- a/src/main/java/top/octopusyan/config/ProxyConfig.java +++ b/src/main/java/top/octopusyan/config/ProxyConfig.java @@ -63,7 +63,7 @@ public class ProxyConfig { UDP, STCP, XTCP, - ; + } public static String getServerPath(String serverName) { diff --git a/src/main/java/top/octopusyan/config/TextValidate.java b/src/main/java/top/octopusyan/config/TextValidate.java index 85e7731..4c42d8e 100644 --- a/src/main/java/top/octopusyan/config/TextValidate.java +++ b/src/main/java/top/octopusyan/config/TextValidate.java @@ -113,7 +113,7 @@ public class TextValidate { RegexValidator validator = new RegexValidator(message); - validator.setRegexPattern("[a-zA-Z0-9_-]{" + min + "," + max + "}$"); + validator.setRegexPattern("[\\w@-_\\.]{" + min + "," + max + "}$"); return validator; } diff --git a/src/main/java/top/octopusyan/controller/LoginController.java b/src/main/java/top/octopusyan/controller/LoginController.java index 5e0d526..f440242 100644 --- a/src/main/java/top/octopusyan/controller/LoginController.java +++ b/src/main/java/top/octopusyan/controller/LoginController.java @@ -16,6 +16,7 @@ import javafx.scene.input.KeyCode; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; +import okhttp3.Call; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.kordamp.ikonli.javafx.FontIcon; @@ -162,8 +163,8 @@ public class LoginController extends BaseController implements Initia // 添加文本校验 accountTextField.getValidators().add(TextValidate.AccoountRequired); - accountTextField.getValidators().add(TextValidate.AccoountValidator); - accountTextField.getValidators().add(TextValidate.getLengthValidator(6, 18, "账号")); +// accountTextField.getValidators().add(TextValidate.AccoountValidator); + accountTextField.getValidators().add(TextValidate.getLengthValidator(6, 25, "账号")); passwordTextField.getValidators().add(TextValidate.PasswordRequired); seePwdTextField.getValidators().add(TextValidate.PasswordRequired); @@ -261,6 +262,11 @@ public class LoginController extends BaseController implements Initia .api(Api.Login) .param(new LoginParam(accountTextField.getText(), tmpPwd.get())) .request(new OnHttpListener() { + @Override + public void onStart(Call call) { + Platform.runLater(() -> loginBtn.setDisable(true)); + } + @Override public void onSucceed(String result) { // 登录出错 @@ -288,6 +294,11 @@ public class LoginController extends BaseController implements Initia public void onFail(Exception e) { } + + @Override + public void onEnd(Call call) { + Platform.runLater(() -> loginBtn.setDisable(false)); + } }); } diff --git a/src/main/java/top/octopusyan/controller/MainController.java b/src/main/java/top/octopusyan/controller/MainController.java index 66e8f84..e71567b 100644 --- a/src/main/java/top/octopusyan/controller/MainController.java +++ b/src/main/java/top/octopusyan/controller/MainController.java @@ -538,7 +538,7 @@ public class MainController extends BaseController implements Initial ProxySetup setup = proxySetupModel.get(); // 整理服务设置 - String serverName = getAccount() + "_" + setup.getSort(); + String serverName = setup.getProxy_name() + "_" + setup.getSort(); setup.setServer_name(ApplicatonStore.getUserToken() + "." + EncryptionUtil.MD5_16(serverName)); setup.setId(null); setup.setRuning(false); @@ -724,7 +724,7 @@ public class MainController extends BaseController implements Initial private void initProxyListView() { ObservableList proxyList = proxyList(); - for (ProxySetup proxy : proxyList.subList(proxyListView.getItems().size(), proxyList.size())) { + for (ProxySetup proxy : proxyList) { setProxyListView(proxyList.indexOf(proxy), proxy); } // 设置选中 @@ -745,29 +745,46 @@ public class MainController extends BaseController implements Initial // 运行状态 itemView.setStatus(setup.isRuning()); // 点击删除 - itemView.getDeleteBtn().setOnMouseClicked(event -> { - if(items.size() == 1) { - AlertUtil.error("最后一个连接不可删除!").show(); - return; - } - - // 关闭连接 - if (proxyList().get(index).isRuning()) { - frpUtilMap.get(String.valueOf(index)).stop(); - } - // 调用删除接口 - if (setup.getId() != null) { - ProxyManager.delete(setup.getId()); - } - // 列表删除 - items.remove(itemView); - }); + itemView.getDeleteBtn().setOnMouseClicked(event -> deleteProxyListItem(itemView)); // 是否选中 if (selectProxy() == index) itemView.getStyleClass().add(PROXY_LIST_ITEM_SELECT_CLASS); // 添加 if (isNew) items.add(index, itemView); } + private void deleteProxyListItem(ProxyListItemView itemView) { + ObservableList items = proxyListView.getItems(); + int index = items.indexOf(itemView); + if (index < 0) return; + if (items.size() == 1) { + AlertUtil.error("最后一个连接不可删除!").show(); + return; + } + + ProxySetup setup = proxyList().get(index); + + // 关闭连接 + String key = String.valueOf(setup.getId()); + FrpManager frpManager = frpUtilMap.get(key); + if (setup.isRuning() || frpManager != null) { + frpManager.stop(); + frpUtilMap.remove(key); + } + // 调用删除接口 + if (setup.getId() != null) { + ProxyManager.delete(setup.getId()); + } + // 列表删除 + items.remove(itemView); + proxyList().remove(setup); + // 重新选择 + if (selectProxy() == index) { + proxyListView.getSelectionModel().select(-1); + proxyListView.getSelectionModel().select(index < items.size() ? index : items.size() - 1); + } else if (selectProxy() > index) + selectProxy(selectProxy() - 1); + } + /** * 启动代理 */ diff --git a/src/main/java/top/octopusyan/manager/FrpManager.java b/src/main/java/top/octopusyan/manager/FrpManager.java index 6b845ad..2d1903d 100644 --- a/src/main/java/top/octopusyan/manager/FrpManager.java +++ b/src/main/java/top/octopusyan/manager/FrpManager.java @@ -174,7 +174,7 @@ public class FrpManager { // 基础配置 StringBuilder stringBuilder = new StringBuilder("["); // 服务名称 - StringBuilder serverName = new StringBuilder(ApplicatonStore.getAccount() + "_" + setup.getSort()); + StringBuilder serverName = new StringBuilder(setup.getProxyName()).append("_").append(setup.getSort()); // p2p 服务名 if (isp2p) { if (setup.isProvider()) { @@ -184,8 +184,6 @@ public class FrpManager { // 访问者 serverName = new StringBuilder(setup.getServerName()).append("_visitor"); } - } else { - serverName.append(ApplicatonStore.getAccount()).append("_").append(setup.getSort()); } stringBuilder.append(serverName).append("]\n"); stringBuilder.append("privilege_mode = true\n")