From f49f2dae43c660b473730ef148f78b439141635d Mon Sep 17 00:00:00 2001 From: J62 Date: Fri, 14 Mar 2025 14:09:42 -0700 Subject: [PATCH] news testing --- client/src/main/java/ctbrec/ui/news/NewsTab.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/news/NewsTab.java b/client/src/main/java/ctbrec/ui/news/NewsTab.java index f80ce1f9..cc0c0885 100644 --- a/client/src/main/java/ctbrec/ui/news/NewsTab.java +++ b/client/src/main/java/ctbrec/ui/news/NewsTab.java @@ -6,9 +6,9 @@ import ctbrec.GlobalThreadPool; import ctbrec.Version; import ctbrec.io.HttpException; import ctbrec.io.json.ObjectMapperFactory; -import ctbrec.ui.CamrecApplication; import ctbrec.ui.controls.Dialogs; import ctbrec.ui.tabs.TabSelectionListener; +import javafx.application.HostServices; import javafx.application.Platform; import javafx.geometry.Insets; import javafx.geometry.Pos; @@ -18,7 +18,9 @@ import javafx.scene.control.ScrollPane; import javafx.scene.control.Tab; import javafx.scene.layout.VBox; import lombok.extern.slf4j.Slf4j; +import okhttp3.OkHttpClient; import okhttp3.Request; +import okhttp3.Response; import org.json.JSONArray; import org.json.JSONObject; @@ -32,11 +34,14 @@ import static ctbrec.io.HttpConstants.USER_AGENT; public class NewsTab extends Tab implements TabSelectionListener { private static final String URL = "https://git.ctbrec.com/api/v1/repos/j62/ctbrec/releases"; private final Config config; + private final HostServices hostServices; private final VBox layout = new VBox(); private final ObjectMapper mapper = ObjectMapperFactory.getMapper(); + private final OkHttpClient httpClient = new OkHttpClient(); - public NewsTab(Config config) { + public NewsTab(Config config, HostServices hostServices) { this.config = config; + this.hostServices = hostServices; setText("Releases"); layout.setMaxWidth(800); layout.setAlignment(Pos.CENTER); @@ -54,7 +59,7 @@ public class NewsTab extends Tab implements TabSelectionListener { .url(URL) .header(USER_AGENT, "ctbrec " + Version.getVersion()) .build(); - try (var response = CamrecApplication.httpClient.execute(request)) { + try (Response response = httpClient.newCall(request).execute()) { if (response.isSuccessful()) { var body = Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string(); log.debug(body); @@ -107,7 +112,7 @@ public class NewsTab extends Tab implements TabSelectionListener { int downloads = asset.optInt("download_count", 0); Hyperlink assetLink = new Hyperlink(assetName + " (" + size / 1024 / 1024 + " MB, " + downloads + " downloads)"); - assetLink.setOnAction(event -> CamrecApplication.getHostServicesInstance().showDocument(downloadUrl)); + assetLink.setOnAction(event -> hostServices.showDocument(downloadUrl)); releasePane.getChildren().add(assetLink); } @@ -123,4 +128,4 @@ public class NewsTab extends Tab implements TabSelectionListener { public void deselected() { // nothing to do } -} \ No newline at end of file +}