mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-06-25 01:20:22 +12:00
Improve font loading checks
This commit is contained in:
parent
147e68efe5
commit
7391310dce
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue