Small update check fixes

This commit is contained in:
crschnick 2024-04-03 10:42:33 +00:00
parent d8ce8ecf8c
commit e916c44f06
4 changed files with 63 additions and 13 deletions

View file

@ -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 <FontIconComp.Structure>{
@Value
public static class Structure implements CompStructure<StackPane> {
FontIcon icon;
StackPane pane;
@Override
public StackPane get() {
return pane;
}
}
private final ObservableValue<String> 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);
}
}

View file

@ -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<TileButtonComp.Structure> {
});
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<TileButtonComp.Structure> {
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)

View file

@ -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;
}

View file

@ -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"));