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 49f38a938b..ae15616d95 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 fce40a02ba..cfe6df73a9 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 ced817d7c0..3e347fba08 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 8bc3ce8cce..37af521347 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 e1e61654fd..d8c288e134 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 899a2de5de..06f7a92402 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 08ee848b65..ab5b4c60e4 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=版本列表源