From 45a85e006b6fae1c429d2974249a358317945f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=9E=E5=BA=90?= <109708109+CiiLu@users.noreply.github.com> Date: Sat, 10 Jan 2026 21:44:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E7=BD=AE=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E5=90=8E=E6=B2=A1=E6=9C=89=E9=81=B5=E5=BE=AA=20`hmcl.?= =?UTF-8?q?font.override`=20`HMCL=5FFONT`=20=E7=AD=89=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#5183)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Glavo --- .../jackhuang/hmcl/setting/FontManager.java | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/FontManager.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/FontManager.java index a73a60257..e772d2b2b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/FontManager.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/FontManager.java @@ -18,6 +18,7 @@ package org.jackhuang.hmcl.setting; import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.scene.text.Font; import org.jackhuang.hmcl.Metadata; @@ -94,31 +95,27 @@ public final class FontManager { return null; }); - private static final ObjectProperty fontProperty; + private static final ObjectProperty font = new SimpleObjectProperty<>(); static { + updateFont(); + + LOG.info("Font: " + (font.get() != null ? font.get().getFamily() : "System")); + } + + private static void updateFont() { String fontFamily = config().getLauncherFontFamily(); if (fontFamily == null) fontFamily = System.getProperty("hmcl.font.override"); if (fontFamily == null) fontFamily = System.getenv("HMCL_FONT"); - FontReference fontReference; if (fontFamily == null) { Font defaultFont = DEFAULT_FONT.get(); - fontReference = defaultFont != null ? new FontReference(defaultFont) : null; - } else - fontReference = new FontReference(fontFamily); - - fontProperty = new SimpleObjectProperty<>(fontReference); - - LOG.info("Font: " + (fontReference != null ? fontReference.getFamily() : "System")); - fontProperty.addListener((obs, oldValue, newValue) -> { - if (newValue != null) - config().setLauncherFontFamily(newValue.getFamily()); - else - config().setLauncherFontFamily(null); - }); + font.set(defaultFont != null ? new FontReference(defaultFont) : null); + } else { + font.set(new FontReference(fontFamily)); + } } private static Font tryLoadDefaultFont(Path dir) { @@ -231,20 +228,17 @@ public final class FontManager { } } - public static ObjectProperty fontProperty() { - return fontProperty; + public static ReadOnlyObjectProperty fontProperty() { + return font; } public static FontReference getFont() { - return fontProperty.get(); - } - - public static void setFont(FontReference font) { - fontProperty.set(font); + return font.get(); } public static void setFontFamily(String fontFamily) { - setFont(fontFamily != null ? new FontReference(fontFamily) : null); + config().setLauncherFontFamily(fontFamily); + updateFont(); } // https://github.com/HMCL-dev/HMCL/issues/4072 @@ -292,3 +286,4 @@ public final class FontManager { private FontManager() { } } +