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 cn.octopusyan.alistgui.config.Constants;
import cn.octopusyan.alistgui.config.Context;
import cn.octopusyan.alistgui.enums.ProxySetup;
import cn.octopusyan.alistgui.manager.ConfigManager;
import cn.octopusyan.alistgui.manager.http.HttpConfig;
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 SYSTEM -> httpConfig.setProxySelector(ProxySelector.getDefault());
case MANUAL -> {
if(ConfigManager.hasProxy()) {
if (ConfigManager.hasProxy()) {
InetSocketAddress unresolved = InetSocketAddress.createUnresolved(
Objects.requireNonNull(ConfigManager.proxyHost()),
ConfigManager.getProxyPort()
@ -50,7 +49,7 @@ public class Application extends javafx.application.Application {
}
}
}
httpConfig.setConnectTimeout(10);
httpConfig.setConnectTimeout(3000);
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.util.JsonUtil;
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.net.InetSocketAddress;

View File

@ -116,6 +116,12 @@ public class AlertUtil {
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
public static <T> ChoiceBuilder<T> choices(String hintText, T... choices) {
ChoiceDialog<T> dialog = new ChoiceDialog<>(choices[0], choices);

View File

@ -1,5 +1,7 @@
package cn.octopusyan.alistgui.util.alert;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.scene.control.Dialog;
import javafx.scene.image.Image;
import javafx.stage.Stage;
@ -10,48 +12,52 @@ import java.util.Objects;
/**
* @author octopus_yan
*/
public abstract class BaseBuilder<T extends Dialog<R>, R> {
T alert;
public abstract class BaseBuilder<T extends BaseBuilder<T, ?>, D extends Dialog<?>> {
D dialog;
public BaseBuilder(T alert, Window mOwner) {
this.alert = alert;
public BaseBuilder(D dialog, Window mOwner) {
this.dialog = dialog;
icon("/assets/logo.png");
if (mOwner != null)
this.alert.initOwner(mOwner);
this.dialog.initOwner(mOwner);
}
public BaseBuilder<T, R> title(String title) {
alert.setTitle(title);
return this;
public T title(String title) {
dialog.setTitle(title);
return (T) this;
}
public BaseBuilder<T, R> header(String header) {
alert.setHeaderText(header);
return this;
public T header(String header) {
dialog.setHeaderText(header);
return (T) this;
}
public BaseBuilder<T, R> content(String content) {
alert.setContentText(content);
return this;
public T content(String content) {
dialog.setContentText(content);
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()));
}
public BaseBuilder<T, R> icon(Image image) {
getStage().getIcons().add(image);
return this;
public T icon(Image image) {
ObservableList<Image> icons = getStage().getIcons();
if (icons.isEmpty()) {
Platform.runLater(() -> icons.add(image));
}
return (T) this;
}
public void show() {
if (alert.isShowing()) {
if (!Objects.equals(alert.getContentText(), alert.getContentText()))
alert.setOnHidden(_ -> show());
if (dialog.isShowing()) {
if (!Objects.equals(dialog.getContentText(), dialog.getContentText()))
dialog.setOnHidden(_ -> show());
}
alert.showAndWait();
dialog.showAndWait();
}
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
*/
public class ChoiceBuilder<R> extends BaseBuilder<ChoiceDialog<R>, R> {
public ChoiceBuilder(ChoiceDialog<R> alert, Window mOwner) {
super(alert, mOwner);
public class ChoiceBuilder<R> extends BaseBuilder<ChoiceBuilder<R>, ChoiceDialog<R>> {
public ChoiceBuilder(ChoiceDialog<R> dialog, Window mOwner) {
super(dialog, mOwner);
}
/**
* AlertUtil.choices
*/
public R getChoice(Collection<R> choices) {
Optional<R> result = alert.showAndWait();
Optional<R> result = dialog.showAndWait();
return result.orElse(null);
}
}

View File

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

View File

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

View File

@ -5,7 +5,8 @@
<property name="CHARSET" value="utf-8"/>
<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-->
<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">