diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserStatusBarComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserStatusBarComp.java index 3734c7de..772deef9 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserStatusBarComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserStatusBarComp.java @@ -44,33 +44,21 @@ public class BrowserStatusBarComp extends SimpleComp { } private Comp createProgressStatus() { - var transferredCount = PlatformThread.sync(Bindings.createStringBinding( - () -> { - return HumanReadableFormat.byteCount( - model.getProgress().getValue().getTransferred(), false); - }, - model.getProgress())); - var allCount = PlatformThread.sync(Bindings.createStringBinding( - () -> { - return HumanReadableFormat.byteCount( - model.getProgress().getValue().getTotal(), true); - }, - model.getProgress())); - var progressComp = new LabelComp(BindingsHelper.persist(Bindings.createStringBinding( - () -> { - if (model.getProgress().getValue() == null - || model.getProgress().getValue().done()) { - return null; - } else { - var name = (model.getProgress().getValue().getName() != null - ? " @ " + model.getProgress().getValue().getName() + " " - : ""); - return transferredCount.getValue() + " / " + allCount.getValue() + name; - } - }, - transferredCount, - allCount, - model.getProgress()))); + var text = BindingsHelper.map(model.getProgress(), p -> { + if (p == null || p.done()) { + return null; + } else { + var transferred = HumanReadableFormat.byteCount( + p.getTransferred(), false); + var all = HumanReadableFormat.byteCount( + p.getTotal(), true); + var name = (p.getName() != null + ? " @ " + p.getName() + " " + : ""); + return transferred + " / " + all + name; + } + }); + var progressComp = new LabelComp(text); return progressComp; } diff --git a/app/src/main/java/io/xpipe/app/fxcomps/impl/LabelComp.java b/app/src/main/java/io/xpipe/app/fxcomps/impl/LabelComp.java index d1fa6d4a..be6801a1 100644 --- a/app/src/main/java/io/xpipe/app/fxcomps/impl/LabelComp.java +++ b/app/src/main/java/io/xpipe/app/fxcomps/impl/LabelComp.java @@ -8,6 +8,9 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.value.ObservableValue; import javafx.geometry.Pos; import javafx.scene.control.Label; +import javafx.util.Subscription; + +import java.util.concurrent.Flow; public class LabelComp extends Comp> { @@ -18,13 +21,15 @@ public class LabelComp extends Comp> { } public LabelComp(ObservableValue text) { - this.text = PlatformThread.sync(text); + this.text = text; } @Override public CompStructure