diff --git a/client/src/main/java/ctbrec/ui/tabs/UpdateTab.java b/client/src/main/java/ctbrec/ui/tabs/UpdateTab.java index 51af2896..7dbf38ac 100644 --- a/client/src/main/java/ctbrec/ui/tabs/UpdateTab.java +++ b/client/src/main/java/ctbrec/ui/tabs/UpdateTab.java @@ -1,5 +1,10 @@ package ctbrec.ui.tabs; +import java.util.concurrent.CompletableFuture; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import ctbrec.io.HttpException; import ctbrec.ui.CamrecApplication; import ctbrec.ui.CamrecApplication.Release; @@ -15,10 +20,8 @@ import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; import okhttp3.Request; import okhttp3.Response; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -public class UpdateTab extends Tab { +public class UpdateTab extends Tab implements TabSelectionListener { private static final Logger LOG = LoggerFactory.getLogger(UpdateTab.class); @@ -37,14 +40,17 @@ public class UpdateTab extends Tab { vbox.setAlignment(Pos.CENTER); changelog = new TextArea(); changelog.setEditable(false); + changelog.setText("Loading changelog..."); vbox.getChildren().add(changelog); VBox.setVgrow(changelog, Priority.ALWAYS); setContent(vbox); + } - new Thread(() -> { + public void loadChangeLog() { + CompletableFuture.runAsync(() -> { Request req = new Request.Builder().url("https://pastebin.com/raw/fiAPtM0s").build(); - try(Response resp = CamrecApplication.httpClient.execute(req)) { - if(resp.isSuccessful()) { + try (Response resp = CamrecApplication.httpClient.execute(req)) { + if (resp.isSuccessful()) { changelog.setText(resp.body().string()); } else { throw new HttpException(resp.code(), resp.message()); @@ -53,6 +59,16 @@ public class UpdateTab extends Tab { LOG.error("Couldn't download the changelog", e1); Dialogs.showError(getTabPane().getScene(), "Communication error", "Couldn't download the changelog", e1); } - }).start(); + }); + } + + @Override + public void selected() { + loadChangeLog(); + } + + @Override + public void deselected() { + // nothing to do } }