Improve font loading checks

This commit is contained in:
crschnick 2024-03-23 12:12:23 +00:00
parent 147e68efe5
commit 7391310dce
3 changed files with 41 additions and 16 deletions

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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) {