优化深色模式支持 (#5283)
This commit is contained in:
@@ -51,8 +51,11 @@ public final class EntryPoint {
|
|||||||
|
|
||||||
setupJavaFXVMOptions();
|
setupJavaFXVMOptions();
|
||||||
|
|
||||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS && !isInsideMacAppBundle())
|
if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS) {
|
||||||
initIcon();
|
System.getProperties().putIfAbsent("apple.awt.application.appearance", "system");
|
||||||
|
if (!isInsideMacAppBundle())
|
||||||
|
initIcon();
|
||||||
|
}
|
||||||
|
|
||||||
checkJavaFX();
|
checkJavaFX();
|
||||||
verifyJavaFX();
|
verifyJavaFX();
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ import org.glavo.monetfx.beans.property.ColorSchemeProperty;
|
|||||||
import org.glavo.monetfx.beans.property.ReadOnlyColorSchemeProperty;
|
import org.glavo.monetfx.beans.property.ReadOnlyColorSchemeProperty;
|
||||||
import org.glavo.monetfx.beans.property.SimpleColorSchemeProperty;
|
import org.glavo.monetfx.beans.property.SimpleColorSchemeProperty;
|
||||||
import org.jackhuang.hmcl.ui.FXUtils;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -65,7 +68,7 @@ public final class Themes {
|
|||||||
if (FXUtils.DARK_MODE != null) {
|
if (FXUtils.DARK_MODE != null) {
|
||||||
yield FXUtils.DARK_MODE.get() ? Brightness.DARK : Brightness.LIGHT;
|
yield FXUtils.DARK_MODE.get() ? Brightness.DARK : Brightness.LIGHT;
|
||||||
} else {
|
} else {
|
||||||
yield Brightness.DEFAULT;
|
yield getDefaultBrightness();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "dark" -> Brightness.DARK;
|
case "dark" -> Brightness.DARK;
|
||||||
@@ -97,6 +100,34 @@ public final class Themes {
|
|||||||
theme.addListener(listener);
|
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) {
|
||||||
|
// If the key does not exist, it means Light mode is used
|
||||||
|
brightness = Brightness.LIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultBrightness = brightness;
|
||||||
|
}
|
||||||
|
|
||||||
public static ObjectExpression<Theme> themeProperty() {
|
public static ObjectExpression<Theme> themeProperty() {
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import org.jackhuang.hmcl.util.Lang;
|
|||||||
import org.jackhuang.hmcl.util.javafx.SafeStringConverter;
|
import org.jackhuang.hmcl.util.javafx.SafeStringConverter;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -87,11 +86,8 @@ public class PersonalizationPage extends StackPane {
|
|||||||
|
|
||||||
brightnessPane.setLeft(left);
|
brightnessPane.setLeft(left);
|
||||||
|
|
||||||
JFXComboBox<String> cboBrightness = new JFXComboBox<>(FXCollections.observableArrayList(
|
JFXComboBox<String> cboBrightness = new JFXComboBox<>();
|
||||||
FXUtils.DARK_MODE != null
|
cboBrightness.getItems().setAll("auto", "light", "dark");
|
||||||
? List.of("auto", "light", "dark")
|
|
||||||
: List.of("light", "dark")
|
|
||||||
));
|
|
||||||
cboBrightness.setConverter(FXUtils.stringConverter(name -> i18n("settings.launcher.brightness." + name)));
|
cboBrightness.setConverter(FXUtils.stringConverter(name -> i18n("settings.launcher.brightness." + name)));
|
||||||
cboBrightness.valueProperty().bindBidirectional(config().themeBrightnessProperty());
|
cboBrightness.valueProperty().bindBidirectional(config().themeBrightnessProperty());
|
||||||
brightnessPane.setRight(cboBrightness);
|
brightnessPane.setRight(cboBrightness);
|
||||||
|
|||||||
Reference in New Issue
Block a user