forked from j62/ctbrec
Use TextArea and Okhttp to show the chnagelog
Instead of using a WebView use TextArea and Okhttp, so that we can get rid of javafx-web
This commit is contained in:
parent
3ab4ef785b
commit
77753bd377
|
@ -3,23 +3,25 @@ package ctbrec.ui;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.ui.CamrecApplication.Release;
|
||||
import ctbrec.ui.controls.Dialogs;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.web.WebEngine;
|
||||
import javafx.scene.web.WebView;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class UpdateTab extends Tab {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(UpdateTab.class);
|
||||
|
||||
private WebView browser;
|
||||
private TextArea changelog;
|
||||
|
||||
public UpdateTab(Release latest) {
|
||||
setText("Update Available");
|
||||
|
@ -32,18 +34,24 @@ public class UpdateTab extends Tab {
|
|||
vbox.getChildren().add(button);
|
||||
VBox.setMargin(button, new Insets(0, 0, 10, 0));
|
||||
vbox.setAlignment(Pos.CENTER);
|
||||
|
||||
browser = new WebView();
|
||||
try {
|
||||
WebEngine webEngine = browser.getEngine();
|
||||
webEngine.load("https://raw.githubusercontent.com/0xboobface/ctbrec/master/CHANGELOG.md");
|
||||
webEngine.setUserDataDirectory(Config.getInstance().getConfigDir());
|
||||
vbox.getChildren().add(browser);
|
||||
VBox.setVgrow(browser, Priority.ALWAYS);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Couldn't load changelog", e);
|
||||
}
|
||||
|
||||
changelog = new TextArea();
|
||||
changelog.setEditable(false);
|
||||
vbox.getChildren().add(changelog);
|
||||
VBox.setVgrow(changelog, Priority.ALWAYS);
|
||||
setContent(vbox);
|
||||
|
||||
new Thread(() -> {
|
||||
Request req = new Request.Builder().url("https://raw.githubusercontent.com/0xboobface/ctbrec/master/CHANGELOG.md").build();
|
||||
try(Response resp = CamrecApplication.httpClient.execute(req)) {
|
||||
if(resp.isSuccessful()) {
|
||||
changelog.setText(resp.body().string());
|
||||
} else {
|
||||
throw new HttpException(resp.code(), resp.message());
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
LOG.error("Couldn't download the changelog", e1);
|
||||
Dialogs.showError("Communication error", "Couldn't download the changelog", e1);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue