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 46141f1185..ef34371ee5 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackManager.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackManager.java @@ -712,6 +712,9 @@ public final class ThemePackManager { 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 97582e640d..b0bb6a9a77 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/theme/Themes.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/theme/Themes.java @@ -112,6 +112,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])); } @@ -192,6 +195,7 @@ public final class Themes { } return switch (themeColorType) { case DEFAULT -> ThemeColor.DEFAULT; + case SYSTEM -> getSystemThemeColor(); case CUSTOM -> fallback; case BACKGROUND -> resolveWallpaperThemeColor(fallback, backgroundType); }; @@ -527,6 +531,15 @@ public final class Themes { 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 c31a062361..d8e7bf57b2 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 @@ -500,6 +500,10 @@ public class PersonalizationPage extends StackPane { 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) { @@ -516,7 +520,11 @@ public class PersonalizationPage extends StackPane { 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 b3a6a5d588..711f6d5bcc 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 1d53f97565..3e2c4d3d09 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 ba6eba3d08..e1d798ad00 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=版本列表源