From 7391310dce3db129d8de13f745382e0ffed8ebf5 Mon Sep 17 00:00:00 2001 From: crschnick Date: Sat, 23 Mar 2024 12:12:23 +0000 Subject: [PATCH] Improve font loading checks --- .../app/core/check/AppFontLoadingCheck.java | 31 +++++++++++++++++++ ...FontCheck.java => AppSystemFontCheck.java} | 15 ++------- .../java/io/xpipe/app/util/PlatformState.java | 11 +++++-- 3 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/io/xpipe/app/core/check/AppFontLoadingCheck.java rename app/src/main/java/io/xpipe/app/core/check/{AppBundledFontCheck.java => AppSystemFontCheck.java} (70%) diff --git a/app/src/main/java/io/xpipe/app/core/check/AppFontLoadingCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppFontLoadingCheck.java new file mode 100644 index 00000000..b251a201 --- /dev/null +++ b/app/src/main/java/io/xpipe/app/core/check/AppFontLoadingCheck.java @@ -0,0 +1,31 @@ +package io.xpipe.app.core.check; + +import io.xpipe.core.util.XPipeInstallation; +import javafx.scene.text.Font; + +public class AppFontLoadingCheck { + + public static void init() { + if (canLoadFonts()) { + return; + } + + if (System.getProperty("prism.fontdir") != null) { + throw new IllegalStateException("Unable to load bundled fonts"); + } + + System.setProperty("prism.fontdir", XPipeInstallation.getBundledFontsPath().toString()); + System.setProperty("prism.embeddedfonts", "true"); + init(); + } + + private static boolean canLoadFonts() { + try { + // This can fail if the found system fonts can somehow not be loaded + Font.getDefault(); + return true; + } catch (Throwable e) { + return false; + } + } +} diff --git a/app/src/main/java/io/xpipe/app/core/check/AppBundledFontCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppSystemFontCheck.java similarity index 70% rename from app/src/main/java/io/xpipe/app/core/check/AppBundledFontCheck.java rename to app/src/main/java/io/xpipe/app/core/check/AppSystemFontCheck.java index 099d5fb8..a6cc3d95 100644 --- a/app/src/main/java/io/xpipe/app/core/check/AppBundledFontCheck.java +++ b/app/src/main/java/io/xpipe/app/core/check/AppSystemFontCheck.java @@ -2,18 +2,17 @@ package io.xpipe.app.core.check; import io.xpipe.core.process.OsType; import io.xpipe.core.util.XPipeInstallation; -import javafx.scene.text.Font; import java.util.concurrent.TimeUnit; -public class AppBundledFontCheck { +public class AppSystemFontCheck { public static void init() { if (OsType.getLocal() != OsType.LINUX) { return; } - if (hasFonts() && canLoadFonts()) { + if (hasFonts()) { return; } @@ -33,14 +32,4 @@ public class AppBundledFontCheck { return false; } } - - private static boolean canLoadFonts() { - try { - // This can fail if the found system fonts can somehow not be loaded - Font.getDefault(); - return true; - } catch (Throwable e) { - return false; - } - } } diff --git a/app/src/main/java/io/xpipe/app/util/PlatformState.java b/app/src/main/java/io/xpipe/app/util/PlatformState.java index a25e0f8c..defcd7a9 100644 --- a/app/src/main/java/io/xpipe/app/util/PlatformState.java +++ b/app/src/main/java/io/xpipe/app/util/PlatformState.java @@ -1,6 +1,7 @@ package io.xpipe.app.util; -import io.xpipe.app.core.check.AppBundledFontCheck; +import io.xpipe.app.core.check.AppSystemFontCheck; +import io.xpipe.app.core.check.AppFontLoadingCheck; import io.xpipe.app.fxcomps.util.PlatformThread; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; @@ -82,7 +83,7 @@ public enum PlatformState { } // Check if we have no fonts and set properties to load bundled ones - AppBundledFontCheck.init(); + AppSystemFontCheck.init(); if (AppPrefs.get() != null) { var s = AppPrefs.get().uiScale().getValue(); @@ -104,9 +105,13 @@ public enum PlatformState { try { CountDownLatch latch = new CountDownLatch(1); Platform.setImplicitExit(false); - Platform.startup(latch::countDown); + Platform.startup(() -> { + latch.countDown(); + }); try { latch.await(); + // Check if we have no fonts and set properties to load bundled ones + AppFontLoadingCheck.init(); PlatformState.setCurrent(PlatformState.RUNNING); return Optional.empty(); } catch (InterruptedException e) {