Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ public static void main(String[] args) {

setupJavaFXVMOptions();

if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS && !isInsideMacAppBundle())
initIcon();
if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS) {
System.getProperties().putIfAbsent("apple.awt.application.appearance", "system");
if (!isInsideMacAppBundle())
initIcon();
}

checkJavaFX();
verifyJavaFX();
Expand Down
33 changes: 32 additions & 1 deletion HMCL/src/main/java/org/jackhuang/hmcl/theme/Themes.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@
import org.glavo.monetfx.beans.property.ReadOnlyColorSchemeProperty;
import org.glavo.monetfx.beans.property.SimpleColorSchemeProperty;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.util.platform.OperatingSystem;
import org.jackhuang.hmcl.util.platform.SystemUtils;
import org.jackhuang.hmcl.util.platform.windows.WinReg;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

import static org.jackhuang.hmcl.setting.ConfigHolder.config;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

/// @author Glavo
public final class Themes {
Expand All @@ -65,7 +69,7 @@ private Brightness getBrightness() {
if (FXUtils.DARK_MODE != null) {
yield FXUtils.DARK_MODE.get() ? Brightness.DARK : Brightness.LIGHT;
} else {
yield Brightness.DEFAULT;
yield getDefaultBrightness();
}
}
case "dark" -> Brightness.DARK;
Expand Down Expand Up @@ -97,6 +101,33 @@ protected Theme computeValue() {
theme.addListener(listener);
}

private static Brightness defaultBrightness;

private static Brightness getDefaultBrightness() {
if (defaultBrightness != null)
return defaultBrightness;

Brightness brightness = Brightness.DEFAULT;
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
WinReg reg = WinReg.INSTANCE;
if (reg != null) {
Object appsUseLightTheme = reg.queryValue(WinReg.HKEY.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme");
if (appsUseLightTheme instanceof Integer value) {
brightness = value == 0 ? Brightness.DARK : Brightness.LIGHT;
}
}
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS) {
try {
String result = SystemUtils.run("/usr/bin/defaults", "read", "-g", "AppleInterfaceStyle").trim();
brightness = "Dark".equalsIgnoreCase(result) ? Brightness.DARK : Brightness.LIGHT;
} catch (Exception e) {
LOG.warning("Failed to get macOS appearance", e);
Comment thread
Glavo marked this conversation as resolved.
Outdated
}
}

return defaultBrightness = brightness;
}

public static ObjectExpression<Theme> themeProperty() {
return theme;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.jackhuang.hmcl.util.javafx.SafeStringConverter;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

Expand Down Expand Up @@ -87,11 +86,8 @@ public PersonalizationPage() {

brightnessPane.setLeft(left);

JFXComboBox<String> cboBrightness = new JFXComboBox<>(FXCollections.observableArrayList(
FXUtils.DARK_MODE != null
? List.of("auto", "light", "dark")
: List.of("light", "dark")
));
JFXComboBox<String> cboBrightness = new JFXComboBox<>();
cboBrightness.getItems().setAll("auto", "light", "dark");
cboBrightness.setConverter(FXUtils.stringConverter(name -> i18n("settings.launcher.brightness." + name)));
cboBrightness.valueProperty().bindBidirectional(config().themeBrightnessProperty());
brightnessPane.setRight(cboBrightness);
Expand Down
Loading