style: 清理代码

This commit is contained in:
octopus_yan 2024-09-08 21:52:01 +08:00
parent d6609a5d75
commit 95404edc92
8 changed files with 50 additions and 37 deletions

View File

@ -3,7 +3,6 @@ package cn.octopusyan.alistgui;
import atlantafx.base.theme.PrimerLight; import atlantafx.base.theme.PrimerLight;
import cn.octopusyan.alistgui.config.Constants; import cn.octopusyan.alistgui.config.Constants;
import cn.octopusyan.alistgui.config.Context; import cn.octopusyan.alistgui.config.Context;
import cn.octopusyan.alistgui.enums.ProxySetup;
import cn.octopusyan.alistgui.manager.ConfigManager; import cn.octopusyan.alistgui.manager.ConfigManager;
import cn.octopusyan.alistgui.manager.http.HttpConfig; import cn.octopusyan.alistgui.manager.http.HttpConfig;
import cn.octopusyan.alistgui.manager.http.HttpUtil; import cn.octopusyan.alistgui.manager.http.HttpUtil;
@ -41,7 +40,7 @@ public class Application extends javafx.application.Application {
case NO_PROXY -> httpConfig.setProxySelector(HttpClient.Builder.NO_PROXY); case NO_PROXY -> httpConfig.setProxySelector(HttpClient.Builder.NO_PROXY);
case SYSTEM -> httpConfig.setProxySelector(ProxySelector.getDefault()); case SYSTEM -> httpConfig.setProxySelector(ProxySelector.getDefault());
case MANUAL -> { case MANUAL -> {
if(ConfigManager.hasProxy()) { if (ConfigManager.hasProxy()) {
InetSocketAddress unresolved = InetSocketAddress.createUnresolved( InetSocketAddress unresolved = InetSocketAddress.createUnresolved(
Objects.requireNonNull(ConfigManager.proxyHost()), Objects.requireNonNull(ConfigManager.proxyHost()),
ConfigManager.getProxyPort() ConfigManager.getProxyPort()
@ -50,7 +49,7 @@ public class Application extends javafx.application.Application {
} }
} }
} }
httpConfig.setConnectTimeout(10); httpConfig.setConnectTimeout(3000);
HttpUtil.init(httpConfig); HttpUtil.init(httpConfig);
} }

View File

@ -4,8 +4,6 @@ import cn.octopusyan.alistgui.enums.ProxySetup;
import cn.octopusyan.alistgui.model.ProxyInfo; import cn.octopusyan.alistgui.model.ProxyInfo;
import cn.octopusyan.alistgui.util.JsonUtil; import cn.octopusyan.alistgui.util.JsonUtil;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
//import com.github.markusbernhardt.proxy.ProxySearch;
//import com.github.markusbernhardt.proxy.selector.misc.BufferedProxySelector;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;

View File

@ -116,6 +116,12 @@ public class AlertUtil {
return new TextInputBuilder(dialog, mOwner); return new TextInputBuilder(dialog, mOwner);
} }
public static TextInputBuilder input(String content, String defaultResult) {
TextInputDialog dialog = new TextInputDialog(defaultResult);
dialog.setContentText(content);
return new TextInputBuilder(dialog, mOwner);
}
@SafeVarargs @SafeVarargs
public static <T> ChoiceBuilder<T> choices(String hintText, T... choices) { public static <T> ChoiceBuilder<T> choices(String hintText, T... choices) {
ChoiceDialog<T> dialog = new ChoiceDialog<>(choices[0], choices); ChoiceDialog<T> dialog = new ChoiceDialog<>(choices[0], choices);

View File

@ -1,5 +1,7 @@
package cn.octopusyan.alistgui.util.alert; package cn.octopusyan.alistgui.util.alert;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.scene.control.Dialog; import javafx.scene.control.Dialog;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -10,48 +12,52 @@ import java.util.Objects;
/** /**
* @author octopus_yan * @author octopus_yan
*/ */
public abstract class BaseBuilder<T extends Dialog<R>, R> { public abstract class BaseBuilder<T extends BaseBuilder<T, ?>, D extends Dialog<?>> {
T alert; D dialog;
public BaseBuilder(T alert, Window mOwner) { public BaseBuilder(D dialog, Window mOwner) {
this.alert = alert; this.dialog = dialog;
icon("/assets/logo.png");
if (mOwner != null) if (mOwner != null)
this.alert.initOwner(mOwner); this.dialog.initOwner(mOwner);
} }
public BaseBuilder<T, R> title(String title) { public T title(String title) {
alert.setTitle(title); dialog.setTitle(title);
return this; return (T) this;
} }
public BaseBuilder<T, R> header(String header) { public T header(String header) {
alert.setHeaderText(header); dialog.setHeaderText(header);
return this; return (T) this;
} }
public BaseBuilder<T, R> content(String content) { public T content(String content) {
alert.setContentText(content); dialog.setContentText(content);
return this; return (T) this;
} }
public BaseBuilder<T, R> icon(String path) { public T icon(String path) {
return icon(new Image(Objects.requireNonNull(this.getClass().getResource(path)).toString())); return icon(new Image(Objects.requireNonNull(this.getClass().getResource(path)).toString()));
} }
public BaseBuilder<T, R> icon(Image image) { public T icon(Image image) {
getStage().getIcons().add(image); ObservableList<Image> icons = getStage().getIcons();
return this; if (icons.isEmpty()) {
Platform.runLater(() -> icons.add(image));
}
return (T) this;
} }
public void show() { public void show() {
if (alert.isShowing()) { if (dialog.isShowing()) {
if (!Objects.equals(alert.getContentText(), alert.getContentText())) if (!Objects.equals(dialog.getContentText(), dialog.getContentText()))
alert.setOnHidden(_ -> show()); dialog.setOnHidden(_ -> show());
} }
alert.showAndWait(); dialog.showAndWait();
} }
private Stage getStage() { private Stage getStage() {
return (Stage) alert.getDialogPane().getScene().getWindow(); return (Stage) dialog.getDialogPane().getScene().getWindow();
} }
} }

View File

@ -9,16 +9,16 @@ import java.util.Optional;
/** /**
* @author octopus_yan * @author octopus_yan
*/ */
public class ChoiceBuilder<R> extends BaseBuilder<ChoiceDialog<R>, R> { public class ChoiceBuilder<R> extends BaseBuilder<ChoiceBuilder<R>, ChoiceDialog<R>> {
public ChoiceBuilder(ChoiceDialog<R> alert, Window mOwner) { public ChoiceBuilder(ChoiceDialog<R> dialog, Window mOwner) {
super(alert, mOwner); super(dialog, mOwner);
} }
/** /**
* AlertUtil.choices * AlertUtil.choices
*/ */
public R getChoice(Collection<R> choices) { public R getChoice(Collection<R> choices) {
Optional<R> result = alert.showAndWait(); Optional<R> result = dialog.showAndWait();
return result.orElse(null); return result.orElse(null);
} }
} }

View File

@ -6,11 +6,13 @@ import javafx.stage.Window;
import java.util.Optional; import java.util.Optional;
/** /**
* 获取用户输入弹窗
*
* @author octopus_yan * @author octopus_yan
*/ */
public class TextInputBuilder extends BaseBuilder<TextInputDialog, String>{ public class TextInputBuilder extends BaseBuilder<TextInputBuilder, TextInputDialog> {
public TextInputBuilder(TextInputDialog alert, Window mOwner) { public TextInputBuilder(TextInputDialog dialog, Window mOwner) {
super(alert, mOwner); super(dialog, mOwner);
} }
/** /**
@ -18,7 +20,7 @@ public class TextInputBuilder extends BaseBuilder<TextInputDialog, String>{
* 如果用户点击了取消按钮,将会返回null * 如果用户点击了取消按钮,将会返回null
*/ */
public String getInput() { public String getInput() {
Optional<String> result = alert.showAndWait(); Optional<String> result = dialog.showAndWait();
return result.orElse(null); return result.orElse(null);
} }
} }

View File

@ -1,4 +1,5 @@
@import "root.css"; @import "root.css";
/************************************************** /**************************************************
* Window Header * Window Header
**************************************************/ **************************************************/

View File

@ -5,7 +5,8 @@
<property name="CHARSET" value="utf-8"/> <property name="CHARSET" value="utf-8"/>
<property name="logback.app" value="alist-gui"/> <property name="logback.app" value="alist-gui"/>
<!-- 彩色日志格式 --> <!-- 彩色日志格式 -->
<property name="CONSOLE_LOG_PATTERN" value="%highlight(%d{YYYY:MM:dd HH:mm:ss.SSS}) ${logback.app} %boldYellow([%thread]) %highlight(%-5level) %cyan(%logger{36}) - %mdc{client} [%X{trace_id}] %msg%n"/> <property name="CONSOLE_LOG_PATTERN"
value="%highlight(%d{YYYY:MM:dd HH:mm:ss.SSS}) ${logback.app} %boldYellow([%thread]) %highlight(%-5level) %cyan(%logger{36}) - %mdc{client} [%X{trace_id}] %msg%n"/>
<!--输出到控制台 ConsoleAppender--> <!--输出到控制台 ConsoleAppender-->
<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender"> <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">