mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-30 00:56:56 +13:00
Improve font loading checks
This commit is contained in:
parent
147e68efe5
commit
7391310dce
3 changed files with 41 additions and 16 deletions
|
@ -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.process.OsType;
|
||||||
import io.xpipe.core.util.XPipeInstallation;
|
import io.xpipe.core.util.XPipeInstallation;
|
||||||
import javafx.scene.text.Font;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class AppBundledFontCheck {
|
public class AppSystemFontCheck {
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
if (OsType.getLocal() != OsType.LINUX) {
|
if (OsType.getLocal() != OsType.LINUX) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasFonts() && canLoadFonts()) {
|
if (hasFonts()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,14 +32,4 @@ public class AppBundledFontCheck {
|
||||||
return false;
|
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;
|
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.fxcomps.util.PlatformThread;
|
||||||
import io.xpipe.app.issue.TrackEvent;
|
import io.xpipe.app.issue.TrackEvent;
|
||||||
import io.xpipe.app.prefs.AppPrefs;
|
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
|
// Check if we have no fonts and set properties to load bundled ones
|
||||||
AppBundledFontCheck.init();
|
AppSystemFontCheck.init();
|
||||||
|
|
||||||
if (AppPrefs.get() != null) {
|
if (AppPrefs.get() != null) {
|
||||||
var s = AppPrefs.get().uiScale().getValue();
|
var s = AppPrefs.get().uiScale().getValue();
|
||||||
|
@ -104,9 +105,13 @@ public enum PlatformState {
|
||||||
try {
|
try {
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
Platform.setImplicitExit(false);
|
Platform.setImplicitExit(false);
|
||||||
Platform.startup(latch::countDown);
|
Platform.startup(() -> {
|
||||||
|
latch.countDown();
|
||||||
|
});
|
||||||
try {
|
try {
|
||||||
latch.await();
|
latch.await();
|
||||||
|
// Check if we have no fonts and set properties to load bundled ones
|
||||||
|
AppFontLoadingCheck.init();
|
||||||
PlatformState.setCurrent(PlatformState.RUNNING);
|
PlatformState.setCurrent(PlatformState.RUNNING);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
Loading…
Reference in a new issue