From db6ba6439e8824ddb9a06d2ca477b08ca8093b36 Mon Sep 17 00:00:00 2001 From: crschnick Date: Mon, 1 May 2023 10:40:16 +0000 Subject: [PATCH] Svg cache fixes [release] --- .../xpipe/app/fxcomps/impl/SvgCacheComp.java | 55 +++++++++---------- .../app/update/XPipeDistributionType.java | 19 ++++--- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/fxcomps/impl/SvgCacheComp.java b/app/src/main/java/io/xpipe/app/fxcomps/impl/SvgCacheComp.java index d7ae21f19..94f1db930 100644 --- a/app/src/main/java/io/xpipe/app/fxcomps/impl/SvgCacheComp.java +++ b/app/src/main/java/io/xpipe/app/fxcomps/impl/SvgCacheComp.java @@ -3,7 +3,8 @@ package io.xpipe.app.fxcomps.impl; import io.xpipe.app.core.AppImages; import io.xpipe.app.fxcomps.SimpleComp; 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.SimpleStringProperty; import javafx.beans.value.ObservableValue; @@ -14,9 +15,6 @@ import javafx.scene.image.WritableImage; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; -import javafx.util.Duration; - -import java.util.concurrent.atomic.AtomicReference; public class SvgCacheComp extends SimpleComp { @@ -51,8 +49,6 @@ public class SvgCacheComp extends SimpleComp { var back = SvgView.create(webViewContent).createWebview(); back.prefWidthProperty().bind(width); back.prefHeightProperty().bind(height); - var animation = new AtomicReference(); - var active = new SimpleObjectProperty(); svgFile.addListener((observable, oldValue, newValue) -> { var cached = cache.getCached(newValue); webViewContent.setValue(newValue != null || cached.isEmpty() ? AppImages.svgImage(newValue) : null); @@ -60,34 +56,35 @@ public class SvgCacheComp extends SimpleComp { back.setVisible(cached.isEmpty()); front.setVisible(cached.isPresent()); - if (animation.get() != null) { - animation.get().stop(); - animation.set(null); + if (cached.isPresent()) { + return; } - var pt = new PauseTransition(); - active.set(pt); - pt.setDuration(Duration.millis(500)); - pt.setOnFinished(actionEvent -> { - if (newValue == null || cache.getCached(newValue).isPresent()) { - return; - } + Platform.runLater(() -> new AnimationTimer() { + int frames = 0; - if (!active.get().equals(pt)) { - return; - } + @Override + 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(); - parameters.setFill(Color.TRANSPARENT); - WritableImage image = back.snapshot(parameters, null); - if (image.getWidth() < 10) { - return; - } + if (cache.getCached(newValue).isPresent()) { + return null; + } - cache.put(newValue, image); - }); - pt.play(); - animation.set(pt); + cache.put(newValue, image); + return null; + }, parameters, null); + stop(); + } + } + }.start()); }); var stack = new StackPane(back, front); diff --git a/app/src/main/java/io/xpipe/app/update/XPipeDistributionType.java b/app/src/main/java/io/xpipe/app/update/XPipeDistributionType.java index 791b69a06..da7a7cca1 100644 --- a/app/src/main/java/io/xpipe/app/update/XPipeDistributionType.java +++ b/app/src/main/java/io/xpipe/app/update/XPipeDistributionType.java @@ -59,14 +59,17 @@ public enum XPipeDistributionType { } try (var sc = LocalStore.getShell()) { - try (var chocoOut = sc.command("choco search --local-only -r xpipe").start()) { - var out = chocoOut.readStdoutDiscardErr(); - if (chocoOut.getExitCode() == 0) { - var split = out.split("\\|"); - if (split.length == 2) { - var version = split[1]; - if (AppProperties.get().getVersion().equals(version)) { - return CHOCO; + if (OsType.getLocal().equals(OsType.WINDOWS)) { + try (var chocoOut = + sc.command("choco search --local-only -r xpipe").start()) { + var out = chocoOut.readStdoutDiscardErr(); + if (chocoOut.getExitCode() == 0) { + var split = out.split("\\|"); + if (split.length == 2) { + var version = split[1]; + if (AppProperties.get().getVersion().equals(version)) { + return CHOCO; + } } } }