mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-24 16:40:25 +00:00
Make webview fail resilient
This commit is contained in:
parent
9ba4c3115a
commit
7309763d42
3 changed files with 32 additions and 18 deletions
|
@ -75,14 +75,17 @@ public class PrettySvgComp extends SimpleComp {
|
|||
ar);
|
||||
|
||||
var stack = new StackPane();
|
||||
var node = storeIcon.createWebview();
|
||||
node.prefWidthProperty().bind(widthProperty);
|
||||
node.maxWidthProperty().bind(widthProperty);
|
||||
node.minWidthProperty().bind(widthProperty);
|
||||
node.prefHeightProperty().bind(heightProperty);
|
||||
node.maxHeightProperty().bind(heightProperty);
|
||||
node.minHeightProperty().bind(heightProperty);
|
||||
stack.getChildren().add(node);
|
||||
var wv = storeIcon.createWebview();
|
||||
if (wv.isPresent()) {
|
||||
var node = wv.get();
|
||||
node.prefWidthProperty().bind(widthProperty);
|
||||
node.maxWidthProperty().bind(widthProperty);
|
||||
node.minWidthProperty().bind(widthProperty);
|
||||
node.prefHeightProperty().bind(heightProperty);
|
||||
node.maxHeightProperty().bind(heightProperty);
|
||||
node.minHeightProperty().bind(heightProperty);
|
||||
stack.getChildren().add(node);
|
||||
}
|
||||
|
||||
Consumer<String> update = val -> {
|
||||
var fixed = val != null
|
||||
|
|
|
@ -3,7 +3,7 @@ package io.xpipe.app.fxcomps.impl;
|
|||
import io.xpipe.app.core.AppProperties;
|
||||
import io.xpipe.app.fxcomps.CompStructure;
|
||||
import io.xpipe.app.fxcomps.util.PlatformThread;
|
||||
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
|
@ -13,12 +13,12 @@ import javafx.scene.Node;
|
|||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.web.WebView;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
|
@ -28,6 +28,8 @@ public class SvgView {
|
|||
private final ObservableValue<Number> height;
|
||||
private final ObservableValue<String> svgContent;
|
||||
|
||||
private static boolean canCreateWebview = true;
|
||||
|
||||
private SvgView(ObservableValue<Number> width, ObservableValue<Number> height, ObservableValue<String> svgContent) {
|
||||
this.width = PlatformThread.sync(width);
|
||||
this.height = PlatformThread.sync(height);
|
||||
|
@ -55,7 +57,20 @@ public class SvgView {
|
|||
}
|
||||
|
||||
private WebView createWebView() {
|
||||
var wv = new WebView();
|
||||
if (!canCreateWebview) {
|
||||
return null;
|
||||
}
|
||||
|
||||
WebView wv;
|
||||
try {
|
||||
// This can happen if we are using a custom JavaFX build without webkit
|
||||
wv = new WebView();
|
||||
} catch (Throwable t) {
|
||||
ErrorEvent.fromThrowable(t).omit().expected().handle();
|
||||
canCreateWebview = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
wv.getEngine()
|
||||
.setUserDataDirectory(
|
||||
AppProperties.get().getDataDir().resolve("webview").toFile());
|
||||
|
@ -109,10 +124,10 @@ public class SvgView {
|
|||
return wv;
|
||||
}
|
||||
|
||||
public WebView createWebview() {
|
||||
public Optional<WebView> createWebview() {
|
||||
var wv = createWebView();
|
||||
wv.getStyleClass().add("svg-comp");
|
||||
return wv;
|
||||
return Optional.ofNullable(wv);
|
||||
}
|
||||
|
||||
@Value
|
||||
|
|
|
@ -25,11 +25,7 @@ if (customJavaFxPath != null) {
|
|||
}
|
||||
}
|
||||
dependencies {
|
||||
javafx name: "org.openjfx:javafx-base"
|
||||
javafx name: "org.openjfx:javafx-controls"
|
||||
javafx name: "org.openjfx:javafx-graphics"
|
||||
javafx name: "org.openjfx:javafx-media"
|
||||
javafx name: "org.openjfx:javafx-web"
|
||||
javafx fileTree(dir: customJavaFxPath, include: '*.jar')
|
||||
}
|
||||
} else {
|
||||
// Always use maven version for now
|
||||
|
|
Loading…
Reference in a new issue