news testing

This commit is contained in:
J62 2025-03-14 14:09:42 -07:00
parent ad386bd5df
commit f49f2dae43
1 changed files with 10 additions and 5 deletions

View File

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