From 67659b8241a26e14a80ceaaf1b31189edbf3ca04 Mon Sep 17 00:00:00 2001 From: Glavo Date: Sun, 12 Jul 2026 23:20:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=BB=E9=A2=98=E8=89=B2?= =?UTF-8?q?=E8=B7=9F=E9=9A=8F=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jackhuang/hmcl/setting/ThemeColorType.java | 3 +++ .../org/jackhuang/hmcl/theme/ThemePackManager.java | 3 +++ .../main/java/org/jackhuang/hmcl/theme/Themes.java | 13 +++++++++++++ .../jackhuang/hmcl/ui/main/PersonalizationPage.java | 10 +++++++++- HMCL/src/main/resources/assets/lang/I18N.properties | 1 + .../main/resources/assets/lang/I18N_zh.properties | 1 + .../resources/assets/lang/I18N_zh_CN.properties | 1 + 7 files changed, 31 insertions(+), 1 deletion(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/ThemeColorType.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/ThemeColorType.java index 49f38a938bc..ae15616d951 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/ThemeColorType.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/ThemeColorType.java @@ -25,6 +25,9 @@ public enum ThemeColorType { /// Uses the built-in launcher default theme color. DEFAULT, + /// Follows the accent color provided by the operating system. + SYSTEM, + /// Uses the custom launcher theme color selected by the user. CUSTOM, diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackManager.java b/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackManager.java index fce40a02ba6..cfe6df73a96 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackManager.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackManager.java @@ -711,6 +711,9 @@ private static ThemeColorSource currentThemeColorSource() throws IOException { if (themeColorType == ThemeColorType.DEFAULT) { return ThemeColorSource.DEFAULT; } + if (themeColorType == ThemeColorType.SYSTEM) { + return ThemeColorSource.custom(Themes.getSystemThemeColor()); + } if (themeColorType == ThemeColorType.BACKGROUND) { if (backgroundType == BackgroundType.THEME_COLOR) { return ThemeColorSource.DEFAULT; diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/theme/Themes.java b/HMCL/src/main/java/org/jackhuang/hmcl/theme/Themes.java index ced817d7c04..3e347fba086 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/theme/Themes.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/theme/Themes.java @@ -115,6 +115,9 @@ public final class Themes { if (FXUtils.DARK_MODE != null) { observables.add(FXUtils.DARK_MODE); } + if (FXUtils.ACCENT_COLOR != null) { + observables.add(FXUtils.ACCENT_COLOR); + } bind(observables.toArray(new Observable[0])); } @@ -195,6 +198,7 @@ static ThemeColor resolveThemeColor( } return switch (themeColorType) { case DEFAULT -> ThemeColor.DEFAULT; + case SYSTEM -> getSystemThemeColor(); case CUSTOM -> fallback; case BACKGROUND -> resolveWallpaperThemeColor(fallback, backgroundType); }; @@ -528,6 +532,15 @@ private static Brightness getDefaultBrightness() { return defaultBrightness = brightness; } + /// Returns the current operating system accent color, or the launcher default when unavailable. + public static ThemeColor getSystemThemeColor() { + if (FXUtils.ACCENT_COLOR == null) { + return ThemeColor.DEFAULT; + } + @Nullable Color accentColor = FXUtils.ACCENT_COLOR.get(); + return accentColor != null ? ThemeColor.of(accentColor) : ThemeColor.DEFAULT; + } + /// Returns the current resolved launcher theme. public static ResolvedTheme getTheme() { return theme.get(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java index 8bc3ce8cce1..37af5213474 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java @@ -445,6 +445,10 @@ public PersonalizationPage() { i18n("settings.launcher.theme_color_type.default"), ThemeColorType.DEFAULT); + var systemColorChoice = new RadioChoiceList.Choice( + i18n("settings.launcher.theme_color_type.system"), + ThemeColorType.SYSTEM); + var customColorChoice = new RadioChoiceList.Choice( i18n("settings.launcher.theme_color_type.custom"), ThemeColorType.CUSTOM) { @@ -461,7 +465,11 @@ protected Node createRightNode() { RadioChoiceList themeColorChoiceList = new RadioChoiceList<>(); themeColorChoiceList.setFallbackValue(ThemeColorType.DEFAULT); - themeColorChoiceList.setChoices(Arrays.asList(defaultColorChoice, customColorChoice, backgroundColorChoice)); + themeColorChoiceList.setChoices(Arrays.asList( + defaultColorChoice, + systemColorChoice, + customColorChoice, + backgroundColorChoice)); JFXButton themeColorOverrideButton = createThemeAppearanceOverrideButton(); themeColorSublist.setTitleRight(themeColorOverrideButton); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index e1e61654fdc..d8c288e134e 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -1606,6 +1606,7 @@ settings.launcher.theme_color_type.background=Follow Background Wallpaper settings.launcher.theme_color_type.custom=Custom Color settings.launcher.theme_color_type.custom.description=Use the color selected above. settings.launcher.theme_color_type.default=Default +settings.launcher.theme_color_type.system=Follow System settings.launcher.title_transparent=Transparent Titlebar settings.launcher.turn_off_animations=Disable Animation settings.launcher.version_list_source=Version List diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 899a2de5de4..06f7a92402e 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -1397,6 +1397,7 @@ settings.launcher.theme_color_type.background=跟隨背景圖片 settings.launcher.theme_color_type.custom=自訂顏色 settings.launcher.theme_color_type.custom.description=使用上方選擇的顏色。 settings.launcher.theme_color_type.default=預設 +settings.launcher.theme_color_type.system=跟隨系統 settings.launcher.title_transparent=標題欄透明 settings.launcher.turn_off_animations=關閉動畫 settings.launcher.version_list_source=版本清單來源 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index 08ee848b65f..ab5b4c60e49 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -1402,6 +1402,7 @@ settings.launcher.theme_color_type.background=跟随背景壁纸 settings.launcher.theme_color_type.custom=自定义颜色 settings.launcher.theme_color_type.custom.description=使用上方选择的颜色。 settings.launcher.theme_color_type.default=默认 +settings.launcher.theme_color_type.system=跟随系统 settings.launcher.title_transparent=标题栏透明 settings.launcher.turn_off_animations=关闭动画 settings.launcher.version_list_source=版本列表源