Remove News and Logging tab

This commit is contained in:
Jafea7 2025-03-24 17:38:34 +11:00
parent 63e3b074d0
commit 2a5a00a53f
6 changed files with 3 additions and 318 deletions

View File

@ -44,10 +44,8 @@ import ctbrec.sites.stripchat.Stripchat;
import ctbrec.sites.winktv.WinkTv;
import ctbrec.sites.xlovecam.XloveCam;
import ctbrec.ui.controls.Dialogs;
import ctbrec.ui.news.NewsTab;
import ctbrec.ui.settings.SettingsTab;
import ctbrec.ui.tabs.*;
import ctbrec.ui.tabs.logging.LoggingTab;
import ctbrec.ui.tabs.recorded.RecordedTab;
import javafx.application.Application;
import javafx.application.HostServices;
@ -268,10 +266,8 @@ public class CamrecApplication extends Application {
tabPane.getTabs().add(new RecentlyWatchedTab(recorder, sites));
}
tabPane.getTabs().add(new SettingsTab(sites, recorder));
tabPane.getTabs().add(new NewsTab(config));
tabPane.getTabs().add(new DonateTabFx());
tabPane.getTabs().add(new HelpTab());
tabPane.getTabs().add(new LoggingTab());
tabPane.setTabDragPolicy(config.getSettings().tabsSortable ? REORDER : FIXED);
restoreTabOrder();

View File

@ -1,49 +0,0 @@
package ctbrec.ui.news;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class Account {
@JsonProperty("emojis")
private List<Object> emojis = null;
@JsonProperty("note")
private String note;
@JsonProperty("bot")
private Boolean bot;
@JsonProperty("created_at")
private String createdAt;
@JsonProperty("avatar")
private String avatar;
@JsonProperty("display_name")
private String displayName;
@JsonProperty("header_static")
private String headerStatic;
@JsonProperty("url")
private String url;
@JsonProperty("following_count")
private Integer followingCount;
@JsonProperty("statuses_count")
private Integer statusesCount;
@JsonProperty("followers_count")
private Integer followersCount;
@JsonProperty("header")
private String header;
@JsonProperty("id")
private String id;
@JsonProperty("locked")
private Boolean locked;
@JsonProperty("avatar_static")
private String avatarStatic;
@JsonProperty("fields")
private List<Object> fields = null;
@JsonProperty("acct")
private String acct;
@JsonProperty("username")
private String username;
}

View File

@ -1,105 +0,0 @@
package ctbrec.ui.news;
import com.fasterxml.jackson.databind.ObjectMapper;
import ctbrec.Config;
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.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.Tab;
import javafx.scene.layout.VBox;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Request;
import org.json.JSONObject;
import java.io.IOException;
import java.util.Objects;
import static ctbrec.ErrorMessages.HTTP_RESPONSE_BODY_IS_NULL;
import static ctbrec.io.HttpConstants.USER_AGENT;
@Slf4j
public class NewsTab extends Tab implements TabSelectionListener {
private static final String ACCESS_TOKEN = "a2804d73a89951a22e0f8483a6fcec8943afd88b7ba17c459c095aa9e6f94fd0";
private static final String URL = "https://mastodon.cloud/api/v1/accounts/480960/statuses?limit=20&exclude_replies=true";
private final Config config;
private final VBox layout = new VBox();
private final ObjectMapper mapper = ObjectMapperFactory.getMapper();
public NewsTab(Config config) {
this.config = config;
setText("News");
layout.setMaxWidth(800);
layout.setAlignment(Pos.CENTER);
setContent(new ScrollPane(layout));
}
@Override
public void selected() {
GlobalThreadPool.submit(this::loadToots);
}
private void loadToots() {
try {
var request = new Request.Builder()
.url(URL)
.header("Authorization", "Bearer " + ACCESS_TOKEN)
.header(USER_AGENT, "ctbrec " + Version.getVersion())
.build();
try (var response = CamrecApplication.httpClient.execute(request)) {
if (response.isSuccessful()) {
var body = Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
log.debug(body);
if (body.startsWith("[")) {
onSuccess(body);
} else if (body.startsWith("{")) {
onError(body);
} else {
throw new IOException("Unexpected response: " + body);
}
} else {
throw new HttpException(response.code(), response.message());
}
}
} catch (IOException e) {
log.info("Error while loading news", e);
Dialogs.showError(getTabPane().getScene(), "News", "Couldn't load news from mastodon", e);
}
}
private void onError(String body) throws IOException {
var json = new JSONObject(body);
if (json.has("error")) {
throw new IOException("Request not successful: " + json.getString("error"));
} else {
throw new IOException("Unexpected response: " + body);
}
}
private void onSuccess(String body) throws IOException {
Status[] statusArray = mapper.readValue(body, Status[].class);
Platform.runLater(() -> {
layout.getChildren().clear();
for (Status status : statusArray) {
if (status.getInReplyToId() == null && !Objects.equals("direct", status.getVisibility())) {
var stp = new StatusPane(status, config.getDateTimeFormatter());
layout.getChildren().add(stp);
VBox.setMargin(stp, new Insets(10));
}
}
});
}
@Override
public void deselected() {
// nothing to do
}
}

View File

@ -1,75 +0,0 @@
package ctbrec.ui.news;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class Status {
@JsonProperty("pinned")
private Boolean pinned;
@JsonProperty("in_reply_to_id")
private Object inReplyToId;
@JsonProperty("favourites_count")
private Integer favouritesCount;
@JsonProperty("media_attachments")
private List<Object> mediaAttachments = null;
@JsonProperty("created_at")
private String createdAt;
@JsonProperty("replies_count")
private Integer repliesCount;
@JsonProperty("language")
private String language;
@JsonProperty("in_reply_to_account_id")
private Object inReplyToAccountId;
@JsonProperty("content")
private String content;
@JsonProperty("reblog")
private Object reblog;
@JsonProperty("spoiler_text")
private String spoilerText;
@JsonProperty("id")
private String id;
@JsonProperty("reblogged")
private Boolean reblogged;
@JsonProperty("muted")
private Boolean muted;
@JsonProperty("emojis")
private List<Object> emojis = null;
@JsonProperty("reblogs_count")
private Integer reblogsCount;
@JsonProperty("visibility")
private String visibility;
@JsonProperty("sensitive")
private Boolean sensitive;
@JsonProperty("uri")
private String uri;
@JsonProperty("url")
private String url;
@JsonProperty("tags")
private List<Object> tags = null;
@JsonProperty("application")
private Object application;
@JsonProperty("favourited")
private Boolean favourited;
@JsonProperty("mentions")
private List<Object> mentions = null;
@JsonProperty("account")
private Account account;
@JsonProperty("card")
private Object card;
public ZonedDateTime getCreationTime() {
String timestamp = getCreatedAt();
var instant = Instant.parse(timestamp);
var time = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault());
return time;
}
}

View File

@ -1,76 +0,0 @@
package ctbrec.ui.news;
import ctbrec.io.HtmlParser;
import ctbrec.ui.DesktopIntegration;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Rectangle;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Set;
public class StatusPane extends StackPane {
TextArea content;
Button reply;
public StatusPane(Status status, DateTimeFormatter formatter) {
String text = HtmlParser.getText("<div>" + status.getContent() + "</div>", "div");
content = new TextArea(text);
content.setMaxHeight(130);
content.setEditable(false);
content.setWrapText(true);
getChildren().add(content);
ZonedDateTime createdAt = status.getCreationTime();
String creationTime = formatter.format(createdAt);
var time = new Label(creationTime);
time.setStyle("-fx-background-color: -fx-base");
time.setOpacity(.7);
time.setPadding(new Insets(3));
time.setOnMouseEntered(evt -> time.setOpacity(1));
time.setOnMouseExited(evt -> time.setOpacity(.7));
getChildren().add(time);
StackPane.setMargin(time, new Insets(5, 5, 5, 10));
StackPane.setAlignment(time, Pos.BOTTOM_LEFT);
var clip = new Rectangle(time.getWidth(), time.getHeight());
clip.heightProperty().bind(time.heightProperty());
clip.widthProperty().bind(time.widthProperty());
clip.setArcHeight(5);
clip.arcWidthProperty().bind(clip.arcHeightProperty());
time.setClip(clip);
reply = new Button("Reply");
reply.setOnAction(evt -> DesktopIntegration.open(status.getUrl()));
getChildren().add(reply);
StackPane.setMargin(reply, new Insets(5, 5, 5, 5));
StackPane.setAlignment(reply, Pos.BOTTOM_RIGHT);
}
@Override
protected void layoutChildren() {
ObservableList<Node> childrenUnmodifiable = content.getChildrenUnmodifiable();
for (Node node : childrenUnmodifiable) {
if (node instanceof ScrollPane scrollPane) {
Set<Node> nodes = scrollPane.lookupAll(".scroll-bar");
for (final Node child : nodes) {
if (child instanceof ScrollBar sb && sb.getOrientation() == Orientation.VERTICAL) {
if (sb.isVisible()) {
StackPane.setMargin(reply, new Insets(5, 22, 5, 5));
} else {
StackPane.setMargin(reply, new Insets(5, 5, 5, 5));
}
}
}
}
}
super.layoutChildren();
}
}

View File

@ -9,12 +9,6 @@
</encoder>
</appender>
<appender name="GUI" class="ctbrec.ui.tabs.logging.CtbrecAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>ctbrec.log</file>
@ -46,13 +40,13 @@
<logger name="ctbrec.io.CookieJarImpl" level="INFO"/>
<logger name="ctbrec.recorder.FFmpeg" level="DEBUG"/>
<logger name="ctbrec.recorder.OnlineMonitor" level="INFO"/>
<logger name="ctbrec.recorder.RecordingFileMonitor" level="TRACE"/>
<logger name="ctbrec.recorder.RecordingFileMonitor" level="INFO"/>
<logger name="ctbrec.recorder.download.dash.DashDownload" level="DEBUG"/>
<logger name="ctbrec.recorder.server.HlsServlet" level="INFO"/>
<logger name="ctbrec.recorder.server.RecorderServlet" level="INFO"/>
<logger name="ctbrec.recorder.ThreadPoolScaler" level="DEBUG"/>
<logger name="ctbrec.ui.ExternalBrowser" level="DEBUG"/>
<logger name="ctbrec.ui.ThumbOverviewTab" level="DEBUG"/>
<logger name="ctbrec.ui.ExternalBrowser" level="INFO"/>
<logger name="ctbrec.ui.ThumbOverviewTab" level="INFO"/>
<logger name="org.eclipse.jetty" level="INFO"/>
</configuration>