mirror of
https://github.com/octopusYan/alist-gui.git
synced 2024-12-05 01:36:43 +08:00
chore: 全局主题更换
This commit is contained in:
parent
a0e5e16afc
commit
1f6ba2d8cc
@ -1,6 +1,5 @@
|
|||||||
package cn.octopusyan.alistgui;
|
package cn.octopusyan.alistgui;
|
||||||
|
|
||||||
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.manager.ConfigManager;
|
import cn.octopusyan.alistgui.manager.ConfigManager;
|
||||||
@ -71,7 +70,7 @@ public class Application extends javafx.application.Application {
|
|||||||
Context.setLanguage(ConfigManager.language());
|
Context.setLanguage(ConfigManager.language());
|
||||||
|
|
||||||
// 主题样式
|
// 主题样式
|
||||||
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
|
Application.setUserAgentStylesheet(ConfigManager.theme().getUserAgentStylesheet());
|
||||||
|
|
||||||
// 启动主界面
|
// 启动主界面
|
||||||
primaryStage.initStyle(StageStyle.TRANSPARENT);
|
primaryStage.initStyle(StageStyle.TRANSPARENT);
|
||||||
|
@ -19,7 +19,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置页面控制器
|
* 设置页面控制器
|
||||||
@ -38,6 +37,8 @@ public class SetupController extends BaseController<VBox> implements Initializab
|
|||||||
@FXML
|
@FXML
|
||||||
public ComboBox<Locale> languageComboBox;
|
public ComboBox<Locale> languageComboBox;
|
||||||
@FXML
|
@FXML
|
||||||
|
public ComboBox<String> themeComboBox;
|
||||||
|
@FXML
|
||||||
public ComboBox<ProxySetup> proxySetupComboBox;
|
public ComboBox<ProxySetup> proxySetupComboBox;
|
||||||
@FXML
|
@FXML
|
||||||
public Pane proxySetupPane;
|
public Pane proxySetupPane;
|
||||||
@ -58,8 +59,8 @@ public class SetupController extends BaseController<VBox> implements Initializab
|
|||||||
@Override
|
@Override
|
||||||
public void initData() {
|
public void initData() {
|
||||||
languageComboBox.setItems(FXCollections.observableList(Context.SUPPORT_LANGUAGE_LIST));
|
languageComboBox.setItems(FXCollections.observableList(Context.SUPPORT_LANGUAGE_LIST));
|
||||||
|
themeComboBox.setItems(FXCollections.observableList(ConfigManager.THEME_NAME_LIST));
|
||||||
proxySetupComboBox.setItems(FXCollections.observableList(List.of(ProxySetup.values())));
|
proxySetupComboBox.setItems(FXCollections.observableList(List.of(ProxySetup.values())));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,6 +71,7 @@ public class SetupController extends BaseController<VBox> implements Initializab
|
|||||||
});
|
});
|
||||||
|
|
||||||
languageComboBox.getSelectionModel().select(ConfigManager.language());
|
languageComboBox.getSelectionModel().select(ConfigManager.language());
|
||||||
|
themeComboBox.getSelectionModel().select(ConfigManager.themeName());
|
||||||
proxySetupComboBox.getSelectionModel().select(ConfigManager.proxySetup());
|
proxySetupComboBox.getSelectionModel().select(ConfigManager.proxySetup());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,13 +79,14 @@ public class SetupController extends BaseController<VBox> implements Initializab
|
|||||||
public void initViewAction() {
|
public void initViewAction() {
|
||||||
autoStartCheckBox.selectedProperty().bindBidirectional(viewModule.autoStartProperty());
|
autoStartCheckBox.selectedProperty().bindBidirectional(viewModule.autoStartProperty());
|
||||||
silentStartupCheckBox.selectedProperty().bindBidirectional(viewModule.silentStartupProperty());
|
silentStartupCheckBox.selectedProperty().bindBidirectional(viewModule.silentStartupProperty());
|
||||||
proxySetupComboBox.getSelectionModel().selectedItemProperty().addListener((_, _, newValue) -> viewModule.proxySetupProperty().set(newValue));
|
languageComboBox.getSelectionModel().selectedItemProperty()
|
||||||
|
.subscribe(locale -> viewModule.languageProperty().set(locale));
|
||||||
|
themeComboBox.getSelectionModel().selectedItemProperty()
|
||||||
|
.subscribe(theme -> viewModule.themeProperty().set(theme));
|
||||||
|
proxySetupComboBox.getSelectionModel().selectedItemProperty()
|
||||||
|
.subscribe((setup) -> viewModule.proxySetupProperty().set(setup));
|
||||||
proxyHost.textProperty().bindBidirectional(viewModule.proxyHostProperty());
|
proxyHost.textProperty().bindBidirectional(viewModule.proxyHostProperty());
|
||||||
proxyPort.textProperty().bindBidirectional(viewModule.proxyPortProperty());
|
proxyPort.textProperty().bindBidirectional(viewModule.proxyPortProperty());
|
||||||
languageComboBox.getSelectionModel().selectedItemProperty().subscribe(locale -> {
|
|
||||||
viewModule.languageProperty().set(locale);
|
|
||||||
logger.info("language changed to {}", locale);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package cn.octopusyan.alistgui.manager;
|
package cn.octopusyan.alistgui.manager;
|
||||||
|
|
||||||
|
import atlantafx.base.theme.*;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.lang.PatternPool;
|
import cn.hutool.core.lang.PatternPool;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
|
import cn.octopusyan.alistgui.Application;
|
||||||
import cn.octopusyan.alistgui.config.Constants;
|
import cn.octopusyan.alistgui.config.Constants;
|
||||||
import cn.octopusyan.alistgui.enums.ProxySetup;
|
import cn.octopusyan.alistgui.enums.ProxySetup;
|
||||||
import cn.octopusyan.alistgui.manager.http.HttpUtil;
|
import cn.octopusyan.alistgui.manager.http.HttpUtil;
|
||||||
@ -20,6 +22,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -36,6 +40,20 @@ public class ConfigManager {
|
|||||||
private static GuiConfig guiConfig;
|
private static GuiConfig guiConfig;
|
||||||
private static UpgradeConfig upgradeConfig;
|
private static UpgradeConfig upgradeConfig;
|
||||||
|
|
||||||
|
public static final String DEFAULT_THEME = "Primer Light";
|
||||||
|
public static List<Theme> THEME_LIST = Arrays.asList(
|
||||||
|
new PrimerLight(), new PrimerDark(),
|
||||||
|
new NordLight(), new NordDark(),
|
||||||
|
new CupertinoLight(), new CupertinoDark(),
|
||||||
|
new Dracula()
|
||||||
|
);
|
||||||
|
public static List<String> THEME_NAME_LIST = Arrays.asList(
|
||||||
|
"Primer Light", "Primer Dark",
|
||||||
|
"Nord Light", "Nord Dark",
|
||||||
|
"Cupertino Light", "Cupertino Dark",
|
||||||
|
"Dracula"
|
||||||
|
);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
|
||||||
@ -59,6 +77,24 @@ public class ConfigManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------{ 主题 }------------------------------------------
|
||||||
|
|
||||||
|
public static String themeName() {
|
||||||
|
return guiConfig.getTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Theme theme() {
|
||||||
|
return THEME_LIST.get(THEME_NAME_LIST.indexOf(themeName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void themeName(String themeName) {
|
||||||
|
int themeIndex = THEME_NAME_LIST.indexOf(themeName);
|
||||||
|
if (themeIndex < 0) return;
|
||||||
|
|
||||||
|
guiConfig.setTheme(themeName);
|
||||||
|
Application.setUserAgentStylesheet(theme().getUserAgentStylesheet());
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean hasProxy() {
|
public static boolean hasProxy() {
|
||||||
if (guiConfig == null)
|
if (guiConfig == null)
|
||||||
return false;
|
return false;
|
||||||
|
@ -20,5 +20,6 @@ public class GuiConfig {
|
|||||||
private ProxyInfo proxyInfo;
|
private ProxyInfo proxyInfo;
|
||||||
private String proxySetup = ProxySetup.NO_PROXY.getName();
|
private String proxySetup = ProxySetup.NO_PROXY.getName();
|
||||||
private String language = ConfigManager.DEFAULT_LANGUAGE.toString();
|
private String language = ConfigManager.DEFAULT_LANGUAGE.toString();
|
||||||
|
private String theme = ConfigManager.DEFAULT_THEME;
|
||||||
private String proxyTestUrl = "http://";
|
private String proxyTestUrl = "http://";
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package cn.octopusyan.alistgui.viewModel;
|
package cn.octopusyan.alistgui.viewModel;
|
||||||
|
|
||||||
import cn.hutool.core.net.NetUtil;
|
|
||||||
import cn.octopusyan.alistgui.base.BaseTask;
|
import cn.octopusyan.alistgui.base.BaseTask;
|
||||||
import cn.octopusyan.alistgui.config.Context;
|
import cn.octopusyan.alistgui.config.Context;
|
||||||
import cn.octopusyan.alistgui.enums.ProxySetup;
|
import cn.octopusyan.alistgui.enums.ProxySetup;
|
||||||
import cn.octopusyan.alistgui.manager.ConfigManager;
|
import cn.octopusyan.alistgui.manager.ConfigManager;
|
||||||
import cn.octopusyan.alistgui.manager.http.HttpUtil;
|
|
||||||
import cn.octopusyan.alistgui.task.ProxyCheckTask;
|
import cn.octopusyan.alistgui.task.ProxyCheckTask;
|
||||||
import cn.octopusyan.alistgui.util.alert.AlertUtil;
|
import cn.octopusyan.alistgui.util.alert.AlertUtil;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
@ -13,7 +11,6 @@ import javafx.beans.property.*;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +22,7 @@ import java.util.Locale;
|
|||||||
public class SetupViewModel {
|
public class SetupViewModel {
|
||||||
private final BooleanProperty autoStart = new SimpleBooleanProperty(ConfigManager.autoStart());
|
private final BooleanProperty autoStart = new SimpleBooleanProperty(ConfigManager.autoStart());
|
||||||
private final BooleanProperty silentStartup = new SimpleBooleanProperty(ConfigManager.silentStartup());
|
private final BooleanProperty silentStartup = new SimpleBooleanProperty(ConfigManager.silentStartup());
|
||||||
|
private final StringProperty theme = new SimpleStringProperty(ConfigManager.themeName());
|
||||||
private final StringProperty proxyHost = new SimpleStringProperty(ConfigManager.proxyHost());
|
private final StringProperty proxyHost = new SimpleStringProperty(ConfigManager.proxyHost());
|
||||||
private final StringProperty proxyPort = new SimpleStringProperty(ConfigManager.proxyPort());
|
private final StringProperty proxyPort = new SimpleStringProperty(ConfigManager.proxyPort());
|
||||||
private final ObjectProperty<Locale> language = new SimpleObjectProperty<>(ConfigManager.language());
|
private final ObjectProperty<Locale> language = new SimpleObjectProperty<>(ConfigManager.language());
|
||||||
@ -33,21 +31,20 @@ public class SetupViewModel {
|
|||||||
|
|
||||||
|
|
||||||
public SetupViewModel() {
|
public SetupViewModel() {
|
||||||
|
theme.addListener((_, _, newValue) -> ConfigManager.themeName(newValue));
|
||||||
autoStart.addListener((_, _, newValue) -> ConfigManager.autoStart(newValue));
|
autoStart.addListener((_, _, newValue) -> ConfigManager.autoStart(newValue));
|
||||||
silentStartup.addListener((_, _, newValue) -> ConfigManager.silentStartup(newValue));
|
silentStartup.addListener((_, _, newValue) -> ConfigManager.silentStartup(newValue));
|
||||||
proxySetup.addListener((_, _, newValue) -> ConfigManager.proxySetup(newValue));
|
proxySetup.addListener((_, _, newValue) -> ConfigManager.proxySetup(newValue));
|
||||||
proxyTestUrl.addListener((_, _, newValue) -> ConfigManager.proxyTestUrl(newValue));
|
proxyTestUrl.addListener((_, _, newValue) -> ConfigManager.proxyTestUrl(newValue));
|
||||||
proxyHost.addListener((_, _, newValue) -> {
|
proxyHost.addListener((_, _, newValue) -> ConfigManager.proxyHost(newValue));
|
||||||
ConfigManager.proxyHost(newValue);
|
proxyPort.addListener((_, _, newValue) -> ConfigManager.proxyPort(newValue));
|
||||||
checkProxy();
|
|
||||||
});
|
|
||||||
proxyPort.addListener((_, _, newValue) -> {
|
|
||||||
ConfigManager.proxyPort(newValue);
|
|
||||||
checkProxy();
|
|
||||||
});
|
|
||||||
language.addListener((_, _, newValue) -> Context.setLanguage(newValue));
|
language.addListener((_, _, newValue) -> Context.setLanguage(newValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StringProperty themeProperty() {
|
||||||
|
return theme;
|
||||||
|
}
|
||||||
|
|
||||||
public BooleanProperty autoStartProperty() {
|
public BooleanProperty autoStartProperty() {
|
||||||
return autoStart;
|
return autoStart;
|
||||||
}
|
}
|
||||||
@ -85,17 +82,6 @@ public class SetupViewModel {
|
|||||||
getProxyCheckTask(checkUrl).execute();
|
getProxyCheckTask(checkUrl).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkProxy() {
|
|
||||||
try {
|
|
||||||
InetSocketAddress address = NetUtil.createAddress(proxyHost.get(), Integer.parseInt(proxyPort.getValue()));
|
|
||||||
if (NetUtil.isOpen(address, 2000)) {
|
|
||||||
HttpUtil.getInstance().proxy(proxySetup.get(), ConfigManager.getProxyInfo());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.debug(STR."host=\{proxyHost.get()},port=\{proxyPort.get()}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ProxyCheckTask getProxyCheckTask(String checkUrl) {
|
private static ProxyCheckTask getProxyCheckTask(String checkUrl) {
|
||||||
var task = new ProxyCheckTask(checkUrl);
|
var task = new ProxyCheckTask(checkUrl);
|
||||||
final var progress = AlertUtil.progress();
|
final var progress = AlertUtil.progress();
|
||||||
|
@ -12,6 +12,10 @@
|
|||||||
</padding>
|
</padding>
|
||||||
<CheckBox fx:id="autoStartCheckBox" text="%setup.auto-start.label"/>
|
<CheckBox fx:id="autoStartCheckBox" text="%setup.auto-start.label"/>
|
||||||
<CheckBox fx:id="silentStartupCheckBox" text="%setup.silent-startup.label"/>
|
<CheckBox fx:id="silentStartupCheckBox" text="%setup.silent-startup.label"/>
|
||||||
|
<HBox alignment="CENTER_LEFT" spacing="10">
|
||||||
|
<Label text="%setup.theme"/>
|
||||||
|
<ComboBox fx:id="themeComboBox"/>
|
||||||
|
</HBox>
|
||||||
<HBox alignment="CENTER_LEFT" spacing="10">
|
<HBox alignment="CENTER_LEFT" spacing="10">
|
||||||
<Label text="%setup.language"/>
|
<Label text="%setup.language"/>
|
||||||
<ComboBox fx:id="languageComboBox"/>
|
<ComboBox fx:id="languageComboBox"/>
|
||||||
|
@ -31,5 +31,6 @@ about.alist.version=AList \u7248\u672C
|
|||||||
about.app.version=GUI \u7248\u672C
|
about.app.version=GUI \u7248\u672C
|
||||||
about.alist.update=\u68C0\u67E5 AList \u7248\u672C
|
about.alist.update=\u68C0\u67E5 AList \u7248\u672C
|
||||||
about.app.update=\u68C0\u67E5 GUI \u7248\u672C
|
about.app.update=\u68C0\u67E5 GUI \u7248\u672C
|
||||||
|
setup.theme=\u4E3B\u9898
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,5 +31,6 @@ about.alist.version=AList Version
|
|||||||
about.app.version=GUI Version
|
about.app.version=GUI Version
|
||||||
about.alist.update=Check AList Version
|
about.alist.update=Check AList Version
|
||||||
about.app.update=Check GUI Version
|
about.app.update=Check GUI Version
|
||||||
|
setup.theme=Theme
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,5 +31,6 @@ about.alist.version=AList \u7248\u672C
|
|||||||
about.app.version=GUI \u7248\u672C
|
about.app.version=GUI \u7248\u672C
|
||||||
about.alist.update=\u68C0\u67E5 AList \u7248\u672C
|
about.alist.update=\u68C0\u67E5 AList \u7248\u672C
|
||||||
about.app.update=\u68C0\u67E5 GUI \u7248\u672C
|
about.app.update=\u68C0\u67E5 GUI \u7248\u672C
|
||||||
|
setup.theme=\u4E3B\u9898
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user