mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-07-15 11:16:13 +12:00
Svg cache fixes [release]
This commit is contained in:
parent
9f4359a4eb
commit
db6ba6439e
|
@ -3,7 +3,8 @@ package io.xpipe.app.fxcomps.impl;
|
||||||
import io.xpipe.app.core.AppImages;
|
import io.xpipe.app.core.AppImages;
|
||||||
import io.xpipe.app.fxcomps.SimpleComp;
|
import io.xpipe.app.fxcomps.SimpleComp;
|
||||||
import io.xpipe.app.fxcomps.util.PlatformThread;
|
import io.xpipe.app.fxcomps.util.PlatformThread;
|
||||||
import javafx.animation.PauseTransition;
|
import javafx.animation.AnimationTimer;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
|
@ -14,9 +15,6 @@ import javafx.scene.image.WritableImage;
|
||||||
import javafx.scene.layout.Region;
|
import javafx.scene.layout.Region;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.util.Duration;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
public class SvgCacheComp extends SimpleComp {
|
public class SvgCacheComp extends SimpleComp {
|
||||||
|
|
||||||
|
@ -51,8 +49,6 @@ public class SvgCacheComp extends SimpleComp {
|
||||||
var back = SvgView.create(webViewContent).createWebview();
|
var back = SvgView.create(webViewContent).createWebview();
|
||||||
back.prefWidthProperty().bind(width);
|
back.prefWidthProperty().bind(width);
|
||||||
back.prefHeightProperty().bind(height);
|
back.prefHeightProperty().bind(height);
|
||||||
var animation = new AtomicReference<PauseTransition>();
|
|
||||||
var active = new SimpleObjectProperty<PauseTransition>();
|
|
||||||
svgFile.addListener((observable, oldValue, newValue) -> {
|
svgFile.addListener((observable, oldValue, newValue) -> {
|
||||||
var cached = cache.getCached(newValue);
|
var cached = cache.getCached(newValue);
|
||||||
webViewContent.setValue(newValue != null || cached.isEmpty() ? AppImages.svgImage(newValue) : null);
|
webViewContent.setValue(newValue != null || cached.isEmpty() ? AppImages.svgImage(newValue) : null);
|
||||||
|
@ -60,34 +56,35 @@ public class SvgCacheComp extends SimpleComp {
|
||||||
back.setVisible(cached.isEmpty());
|
back.setVisible(cached.isEmpty());
|
||||||
front.setVisible(cached.isPresent());
|
front.setVisible(cached.isPresent());
|
||||||
|
|
||||||
if (animation.get() != null) {
|
if (cached.isPresent()) {
|
||||||
animation.get().stop();
|
|
||||||
animation.set(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
var pt = new PauseTransition();
|
|
||||||
active.set(pt);
|
|
||||||
pt.setDuration(Duration.millis(500));
|
|
||||||
pt.setOnFinished(actionEvent -> {
|
|
||||||
if (newValue == null || cache.getCached(newValue).isPresent()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!active.get().equals(pt)) {
|
Platform.runLater(() -> new AnimationTimer() {
|
||||||
return;
|
int frames = 0;
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(long l) {
|
||||||
|
if (++frames == 2) {
|
||||||
SnapshotParameters parameters = new SnapshotParameters();
|
SnapshotParameters parameters = new SnapshotParameters();
|
||||||
parameters.setFill(Color.TRANSPARENT);
|
parameters.setFill(Color.TRANSPARENT);
|
||||||
WritableImage image = back.snapshot(parameters, null);
|
back.snapshot(snapshotResult -> {
|
||||||
|
WritableImage image = snapshotResult.getImage();
|
||||||
if (image.getWidth() < 10) {
|
if (image.getWidth() < 10) {
|
||||||
return;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cache.getCached(newValue).isPresent()) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.put(newValue, image);
|
cache.put(newValue, image);
|
||||||
});
|
return null;
|
||||||
pt.play();
|
}, parameters, null);
|
||||||
animation.set(pt);
|
stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start());
|
||||||
});
|
});
|
||||||
|
|
||||||
var stack = new StackPane(back, front);
|
var stack = new StackPane(back, front);
|
||||||
|
|
|
@ -59,7 +59,9 @@ public enum XPipeDistributionType {
|
||||||
}
|
}
|
||||||
|
|
||||||
try (var sc = LocalStore.getShell()) {
|
try (var sc = LocalStore.getShell()) {
|
||||||
try (var chocoOut = sc.command("choco search --local-only -r xpipe").start()) {
|
if (OsType.getLocal().equals(OsType.WINDOWS)) {
|
||||||
|
try (var chocoOut =
|
||||||
|
sc.command("choco search --local-only -r xpipe").start()) {
|
||||||
var out = chocoOut.readStdoutDiscardErr();
|
var out = chocoOut.readStdoutDiscardErr();
|
||||||
if (chocoOut.getExitCode() == 0) {
|
if (chocoOut.getExitCode() == 0) {
|
||||||
var split = out.split("\\|");
|
var split = out.split("\\|");
|
||||||
|
@ -71,6 +73,7 @@ public enum XPipeDistributionType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (OsType.getLocal().equals(OsType.MACOS)) {
|
if (OsType.getLocal().equals(OsType.MACOS)) {
|
||||||
try (var brewOut = sc.command("brew list --casks --versions").start()) {
|
try (var brewOut = sc.command("brew list --casks --versions").start()) {
|
||||||
|
|
Loading…
Reference in a new issue