Compare commits

..

No commits in common. "f49f2dae43c660b473730ef148f78b439141635d" and "9a5a469ad06fd5b7575525a5a78f2a9ab1cdfd9b" have entirely different histories.

2 changed files with 6 additions and 12 deletions

View File

@ -268,8 +268,7 @@ public class CamrecApplication extends Application {
tabPane.getTabs().add(new RecentlyWatchedTab(recorder, sites)); tabPane.getTabs().add(new RecentlyWatchedTab(recorder, sites));
} }
tabPane.getTabs().add(new SettingsTab(sites, recorder)); tabPane.getTabs().add(new SettingsTab(sites, recorder));
//tabPane.getTabs().add(new NewsTab(config)); tabPane.getTabs().add(new NewsTab(config));
tabPane.getTabs().add(new NewsTab(config, getHostServices()));
tabPane.getTabs().add(new DonateTabFx()); tabPane.getTabs().add(new DonateTabFx());
tabPane.getTabs().add(new HelpTab()); tabPane.getTabs().add(new HelpTab());
tabPane.getTabs().add(new LoggingTab()); tabPane.getTabs().add(new LoggingTab());

View File

@ -6,9 +6,9 @@ import ctbrec.GlobalThreadPool;
import ctbrec.Version; import ctbrec.Version;
import ctbrec.io.HttpException; import ctbrec.io.HttpException;
import ctbrec.io.json.ObjectMapperFactory; import ctbrec.io.json.ObjectMapperFactory;
import ctbrec.ui.CamrecApplication;
import ctbrec.ui.controls.Dialogs; import ctbrec.ui.controls.Dialogs;
import ctbrec.ui.tabs.TabSelectionListener; import ctbrec.ui.tabs.TabSelectionListener;
import javafx.application.HostServices;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
@ -18,9 +18,7 @@ import javafx.scene.control.ScrollPane;
import javafx.scene.control.Tab; import javafx.scene.control.Tab;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -34,14 +32,11 @@ import static ctbrec.io.HttpConstants.USER_AGENT;
public class NewsTab extends Tab implements TabSelectionListener { public class NewsTab extends Tab implements TabSelectionListener {
private static final String URL = "https://git.ctbrec.com/api/v1/repos/j62/ctbrec/releases"; private static final String URL = "https://git.ctbrec.com/api/v1/repos/j62/ctbrec/releases";
private final Config config; private final Config config;
private final HostServices hostServices;
private final VBox layout = new VBox(); private final VBox layout = new VBox();
private final ObjectMapper mapper = ObjectMapperFactory.getMapper(); private final ObjectMapper mapper = ObjectMapperFactory.getMapper();
private final OkHttpClient httpClient = new OkHttpClient();
public NewsTab(Config config, HostServices hostServices) { public NewsTab(Config config) {
this.config = config; this.config = config;
this.hostServices = hostServices;
setText("Releases"); setText("Releases");
layout.setMaxWidth(800); layout.setMaxWidth(800);
layout.setAlignment(Pos.CENTER); layout.setAlignment(Pos.CENTER);
@ -59,7 +54,7 @@ public class NewsTab extends Tab implements TabSelectionListener {
.url(URL) .url(URL)
.header(USER_AGENT, "ctbrec " + Version.getVersion()) .header(USER_AGENT, "ctbrec " + Version.getVersion())
.build(); .build();
try (Response response = httpClient.newCall(request).execute()) { try (var response = CamrecApplication.httpClient.execute(request)) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
var body = Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string(); var body = Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
log.debug(body); log.debug(body);
@ -112,7 +107,7 @@ public class NewsTab extends Tab implements TabSelectionListener {
int downloads = asset.optInt("download_count", 0); int downloads = asset.optInt("download_count", 0);
Hyperlink assetLink = new Hyperlink(assetName + " (" + size / 1024 / 1024 + " MB, " + downloads + " downloads)"); Hyperlink assetLink = new Hyperlink(assetName + " (" + size / 1024 / 1024 + " MB, " + downloads + " downloads)");
assetLink.setOnAction(event -> hostServices.showDocument(downloadUrl)); assetLink.setOnAction(event -> CamrecApplication.getHostServicesInstance().showDocument(downloadUrl));
releasePane.getChildren().add(assetLink); releasePane.getChildren().add(assetLink);
} }