Rework bundled fonts handling

This commit is contained in:
crschnick
2024-01-03 06:31:13 +00:00
parent 784bff8031
commit 8d080bee1e
6 changed files with 40 additions and 33 deletions

View File

@@ -0,0 +1,34 @@
package io.xpipe.app.core;
import io.xpipe.core.process.OsType;
import io.xpipe.core.util.XPipeInstallation;
import java.util.concurrent.TimeUnit;
public class AppBundledFonts {
public static void init() {
if (OsType.getLocal() != OsType.LINUX) {
return;
}
if (hasFonts()) {
return;
}
System.setProperty("prism.fontdir", XPipeInstallation.getBundledFontsPath().toString());
System.setProperty("prism.embeddedfonts", "true");
}
private static boolean hasFonts() {
var fc = new ProcessBuilder("fc-match").redirectError(ProcessBuilder.Redirect.DISCARD);
try {
var proc = fc.start();
var out = new String(proc.getInputStream().readAllBytes());
proc.waitFor(1, TimeUnit.SECONDS);
return proc.exitValue() == 0 && !out.isEmpty();
} catch (Exception e) {
return false;
}
}
}

View File

@@ -68,11 +68,6 @@ public class AppProperties {
}
}
public static void setDynamicProperties() {
System.setProperty("prism.fontdir", XPipeInstallation.getBundledFontsPath().toString());
System.setProperty("prism.embeddedfonts", "true");
}
public static void logArguments(String[] args) {
TrackEvent.withInfo("Detected arguments")
.tag("list", Arrays.asList(args))

View File

@@ -104,7 +104,6 @@ public abstract class OperationMode {
AppProperties.logArguments(args);
AppProperties.logSystemProperties();
AppProperties.logPassedProperties();
AppProperties.setDynamicProperties();
XPipeSystemId.init();
AppFontCheck.check();
TrackEvent.info("mode", "Finished initial setup");

View File

@@ -1,5 +1,6 @@
package io.xpipe.app.fxcomps.impl;
import atlantafx.base.controls.PasswordTextField;
import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.fxcomps.CompStructure;
import io.xpipe.app.fxcomps.SimpleCompStructure;
@@ -7,7 +8,6 @@ import io.xpipe.app.fxcomps.util.PlatformThread;
import io.xpipe.app.util.SecretHelper;
import io.xpipe.core.util.SecretValue;
import javafx.beans.property.Property;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import java.util.Objects;
@@ -26,7 +26,7 @@ public class SecretFieldComp extends Comp<CompStructure<TextField>> {
@Override
public CompStructure<TextField> createBase() {
var text = new PasswordField();
var text = new PasswordTextField();
text.getStyleClass().add("secret-field-comp");
text.setText(value.getValue() != null ? value.getValue().getSecretValue() : null);
text.textProperty().addListener((c, o, n) -> {

View File

@@ -1,25 +0,0 @@
package io.xpipe.app.prefs;
import com.dlsc.formsfx.model.structure.DataField;
import com.dlsc.formsfx.view.controls.SimplePasswordControl;
import io.xpipe.app.util.SecretHelper;
import io.xpipe.core.util.SecretValue;
import javafx.beans.property.Property;
public class SecretField
extends DataField<Property<SecretValue>, SecretValue, com.dlsc.formsfx.model.structure.PasswordField> {
protected SecretField(Property<SecretValue> valueProperty, Property<SecretValue> persistentValueProperty) {
super(valueProperty, persistentValueProperty);
stringConverter = new AbstractStringConverter<>() {
@Override
public SecretValue fromString(String string) {
return SecretHelper.encrypt(string);
}
};
rendererSupplier = () -> new SimplePasswordControl();
userInput.set(stringConverter.toString(value.getValue()));
}
}

View File

@@ -1,5 +1,6 @@
package io.xpipe.app.util;
import io.xpipe.app.core.AppBundledFonts;
import io.xpipe.app.fxcomps.util.PlatformThread;
import io.xpipe.app.issue.TrackEvent;
import javafx.application.Platform;
@@ -75,6 +76,9 @@ public enum PlatformState {
return Optional.of(e);
}
// Check if we have no fonts and set properties to load bundled ones
AppBundledFonts.init();
try {
CountDownLatch latch = new CountDownLatch(1);
Platform.setImplicitExit(false);