From e916c44f067f349b8334e0cc1e968403601030e6 Mon Sep 17 00:00:00 2001 From: crschnick Date: Wed, 3 Apr 2024 10:42:33 +0000 Subject: [PATCH] Small update check fixes --- .../io/xpipe/app/comp/base/FontIconComp.java | 48 +++++++++++++++++++ .../xpipe/app/comp/base/TileButtonComp.java | 18 +++---- .../io/xpipe/app/prefs/UpdateCheckComp.java | 4 +- .../app/update/UpdateAvailableAlert.java | 6 +++ 4 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/io/xpipe/app/comp/base/FontIconComp.java diff --git a/app/src/main/java/io/xpipe/app/comp/base/FontIconComp.java b/app/src/main/java/io/xpipe/app/comp/base/FontIconComp.java new file mode 100644 index 00000000..1176409d --- /dev/null +++ b/app/src/main/java/io/xpipe/app/comp/base/FontIconComp.java @@ -0,0 +1,48 @@ +package io.xpipe.app.comp.base; + +import io.xpipe.app.fxcomps.Comp; +import io.xpipe.app.fxcomps.CompStructure; +import io.xpipe.app.fxcomps.SimpleCompStructure; +import io.xpipe.app.fxcomps.util.BindingsHelper; +import io.xpipe.app.fxcomps.util.PlatformThread; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.value.ObservableValue; +import javafx.scene.layout.StackPane; +import lombok.AllArgsConstructor; +import lombok.Value; +import org.kordamp.ikonli.javafx.FontIcon; + +@AllArgsConstructor +public class FontIconComp extends Comp { + + @Value + public static class Structure implements CompStructure { + + FontIcon icon; + StackPane pane; + + @Override + public StackPane get() { + return pane; + } + } + + private final ObservableValue icon; + + public FontIconComp(String icon) { + this.icon = new SimpleStringProperty(icon); + } + + @Override + public FontIconComp.Structure createBase() { + var fi = new FontIcon(); + var obs = PlatformThread.sync(icon); + BindingsHelper.linkPersistently(fi, obs); + obs.subscribe(val -> { + fi.setIconLiteral(val); + }); + + var pane = new StackPane(fi); + return new FontIconComp.Structure(fi, pane); + } +} diff --git a/app/src/main/java/io/xpipe/app/comp/base/TileButtonComp.java b/app/src/main/java/io/xpipe/app/comp/base/TileButtonComp.java index 78da5d79..cb6b50be 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/TileButtonComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/TileButtonComp.java @@ -4,6 +4,7 @@ import io.xpipe.app.core.AppFont; import io.xpipe.app.core.AppI18n; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.fxcomps.CompStructure; +import io.xpipe.app.fxcomps.util.BindingsHelper; import io.xpipe.app.fxcomps.util.PlatformThread; import javafx.beans.binding.Bindings; import javafx.beans.property.SimpleStringProperty; @@ -12,7 +13,6 @@ import javafx.event.ActionEvent; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.HBox; -import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import lombok.AllArgsConstructor; import lombok.Builder; @@ -47,20 +47,16 @@ public class TileButtonComp extends Comp { }); var header = new Label(); - header.textProperty().bind(PlatformThread.sync(name)); + BindingsHelper.bindStrong(header.textProperty(), PlatformThread.sync(name)); var desc = new Label(); - desc.textProperty().bind(PlatformThread.sync(description)); + BindingsHelper.bindStrong(desc.textProperty(), PlatformThread.sync(description)); AppFont.small(desc); desc.setOpacity(0.65); var text = new VBox(header, desc); text.setSpacing(2); - var fi = new FontIcon(); - PlatformThread.sync(icon).subscribe(val -> { - fi.setIconLiteral(val); - }); - - var pane = new StackPane(fi); + var fi = new FontIconComp(icon).createStructure(); + var pane = fi.getPane(); var hbox = new HBox(pane, text); hbox.setSpacing(8); pane.prefWidthProperty() @@ -75,11 +71,11 @@ public class TileButtonComp extends Comp { desc.heightProperty())); pane.prefHeightProperty().addListener((c, o, n) -> { var size = Math.min(n.intValue(), 100); - fi.setIconSize((int) (size * 0.55)); + fi.getIcon().setIconSize((int) (size * 0.55)); }); bt.setGraphic(hbox); return Structure.builder() - .graphic(fi) + .graphic(fi.getIcon()) .button(bt) .content(hbox) .name(header) diff --git a/app/src/main/java/io/xpipe/app/prefs/UpdateCheckComp.java b/app/src/main/java/io/xpipe/app/prefs/UpdateCheckComp.java index 5d6241b2..339a7783 100644 --- a/app/src/main/java/io/xpipe/app/prefs/UpdateCheckComp.java +++ b/app/src/main/java/io/xpipe/app/prefs/UpdateCheckComp.java @@ -27,7 +27,7 @@ public class UpdateCheckComp extends SimpleComp { XPipeDistributionType.get().getUpdateHandler().getPreparedUpdate())); } - private void restart() { + private void performUpdateAndRestart() { XPipeDistributionType.get().getUpdateHandler().refreshUpdateCheckSilent(); UpdateAvailableAlert.showIfNeeded(); } @@ -82,7 +82,7 @@ public class UpdateCheckComp extends SimpleComp { return new TileButtonComp(name, description, graphic, actionEvent -> { actionEvent.consume(); if (updateReady.getValue()) { - restart(); + performUpdateAndRestart(); return; } diff --git a/app/src/main/java/io/xpipe/app/update/UpdateAvailableAlert.java b/app/src/main/java/io/xpipe/app/update/UpdateAvailableAlert.java index dcc83c3e..a2fb3f22 100644 --- a/app/src/main/java/io/xpipe/app/update/UpdateAvailableAlert.java +++ b/app/src/main/java/io/xpipe/app/update/UpdateAvailableAlert.java @@ -18,6 +18,12 @@ public class UpdateAvailableAlert { return; } + // Check whether we still have the latest version prepared + uh.refreshUpdateCheckSilent(); + if (uh.getPreparedUpdate().getValue() == null) { + return; + } + var u = uh.getPreparedUpdate().getValue(); var update = AppWindowHelper.showBlockingAlert(alert -> { alert.setTitle(AppI18n.get("updateReadyAlertTitle"));