Svg cache fixes [release]

This commit is contained in:
crschnick 2023-05-01 10:40:16 +00:00
parent 9f4359a4eb
commit db6ba6439e
2 changed files with 37 additions and 37 deletions

View file

@ -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(); return;
animation.set(null);
} }
var pt = new PauseTransition(); Platform.runLater(() -> new AnimationTimer() {
active.set(pt); int frames = 0;
pt.setDuration(Duration.millis(500));
pt.setOnFinished(actionEvent -> {
if (newValue == null || cache.getCached(newValue).isPresent()) {
return;
}
if (!active.get().equals(pt)) { @Override
return; public void handle(long l) {
} if (++frames == 2) {
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
back.snapshot(snapshotResult -> {
WritableImage image = snapshotResult.getImage();
if (image.getWidth() < 10) {
return null;
}
SnapshotParameters parameters = new SnapshotParameters(); if (cache.getCached(newValue).isPresent()) {
parameters.setFill(Color.TRANSPARENT); return null;
WritableImage image = back.snapshot(parameters, null); }
if (image.getWidth() < 10) {
return;
}
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);

View file

@ -59,14 +59,17 @@ 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)) {
var out = chocoOut.readStdoutDiscardErr(); try (var chocoOut =
if (chocoOut.getExitCode() == 0) { sc.command("choco search --local-only -r xpipe").start()) {
var split = out.split("\\|"); var out = chocoOut.readStdoutDiscardErr();
if (split.length == 2) { if (chocoOut.getExitCode() == 0) {
var version = split[1]; var split = out.split("\\|");
if (AppProperties.get().getVersion().equals(version)) { if (split.length == 2) {
return CHOCO; var version = split[1];
if (AppProperties.get().getVersion().equals(version)) {
return CHOCO;
}
} }
} }
} }