From 2a5a00a53ff3e0ca4a0893bdbe529d3c296542a7 Mon Sep 17 00:00:00 2001 From: Jafea7 Date: Mon, 24 Mar 2025 17:38:34 +1100 Subject: [PATCH] Remove News and Logging tab --- .../java/ctbrec/ui/CamrecApplication.java | 4 - .../src/main/java/ctbrec/ui/news/Account.java | 49 -------- .../src/main/java/ctbrec/ui/news/NewsTab.java | 105 ------------------ .../src/main/java/ctbrec/ui/news/Status.java | 75 ------------- .../main/java/ctbrec/ui/news/StatusPane.java | 76 ------------- client/src/main/resources/logback.xml | 12 +- 6 files changed, 3 insertions(+), 318 deletions(-) delete mode 100644 client/src/main/java/ctbrec/ui/news/Account.java delete mode 100644 client/src/main/java/ctbrec/ui/news/NewsTab.java delete mode 100644 client/src/main/java/ctbrec/ui/news/Status.java delete mode 100644 client/src/main/java/ctbrec/ui/news/StatusPane.java diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index a10e5d4e..d2857f6e 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -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(); diff --git a/client/src/main/java/ctbrec/ui/news/Account.java b/client/src/main/java/ctbrec/ui/news/Account.java deleted file mode 100644 index 8b5db643..00000000 --- a/client/src/main/java/ctbrec/ui/news/Account.java +++ /dev/null @@ -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 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 fields = null; - @JsonProperty("acct") - private String acct; - @JsonProperty("username") - private String username; -} diff --git a/client/src/main/java/ctbrec/ui/news/NewsTab.java b/client/src/main/java/ctbrec/ui/news/NewsTab.java deleted file mode 100644 index 152cd693..00000000 --- a/client/src/main/java/ctbrec/ui/news/NewsTab.java +++ /dev/null @@ -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 - } -} diff --git a/client/src/main/java/ctbrec/ui/news/Status.java b/client/src/main/java/ctbrec/ui/news/Status.java deleted file mode 100644 index 8bf4c97d..00000000 --- a/client/src/main/java/ctbrec/ui/news/Status.java +++ /dev/null @@ -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 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 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 tags = null; - @JsonProperty("application") - private Object application; - @JsonProperty("favourited") - private Boolean favourited; - @JsonProperty("mentions") - private List 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; - } -} diff --git a/client/src/main/java/ctbrec/ui/news/StatusPane.java b/client/src/main/java/ctbrec/ui/news/StatusPane.java deleted file mode 100644 index afb4b763..00000000 --- a/client/src/main/java/ctbrec/ui/news/StatusPane.java +++ /dev/null @@ -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("
" + status.getContent() + "
", "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 childrenUnmodifiable = content.getChildrenUnmodifiable(); - for (Node node : childrenUnmodifiable) { - if (node instanceof ScrollPane scrollPane) { - Set 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(); - } -} diff --git a/client/src/main/resources/logback.xml b/client/src/main/resources/logback.xml index 69b16dfd..21a0cffb 100644 --- a/client/src/main/resources/logback.xml +++ b/client/src/main/resources/logback.xml @@ -9,12 +9,6 @@ - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - ctbrec.log @@ -46,13 +40,13 @@ - + - - + +