Move Help/Donate to Settings side menu

This commit is contained in:
Jafea7 2025-04-07 14:59:14 +10:00
parent d2fc18faf1
commit 97c6d5d915
3 changed files with 77 additions and 29 deletions

View File

@ -256,8 +256,6 @@ public class CamrecApplication extends Application {
tabPane.getTabs().add(new RecentlyWatchedTab(recorder, sites));
}
tabPane.getTabs().add(new SettingsTab(sites, recorder));
tabPane.getTabs().add(new DonateTabFx());
tabPane.getTabs().add(new HelpTab());
tabPane.setTabDragPolicy(config.getSettings().tabsSortable ? REORDER : FIXED);
restoreTabOrder();

View File

@ -15,6 +15,8 @@ import ctbrec.ui.SiteUiFactory;
import ctbrec.ui.controls.range.DiscreteRange;
import ctbrec.ui.settings.api.*;
import ctbrec.ui.sites.ConfigUI;
import ctbrec.ui.tabs.HelpTab;
import ctbrec.ui.tabs.DonateTabFx;
import ctbrec.ui.tabs.TabSelectionListener;
import javafx.animation.FadeTransition;
import javafx.animation.PauseTransition;
@ -332,7 +334,8 @@ public class SettingsTab extends Tab implements TabSelectionListener {
Setting.of("", ignoreList)),
Group.of("Text Filters",
Setting.of("Blacklist", filterBlacklist, "Default list of blacklist filters for site views, space seperated"),
Setting.of("Whitelist", filterWhitelist, "Default list of whitelist filters for site views, space seperated"))), Category.of("Sites", siteCategories.toArray(new Category[0])),
Setting.of("Whitelist", filterWhitelist, "Default list of whitelist filters for site views, space seperated"))),
Category.of("Sites", siteCategories.toArray(new Category[0])),
Category.of("Proxy",
Group.of("Proxy",
Setting.of("Type", proxyType).needsRestart(),
@ -364,7 +367,9 @@ public class SettingsTab extends Tab implements TabSelectionListener {
Setting.of("Log hlsdl output", loghlsdlOutput, "Log hlsdl output to files in the system's temp directory")),
Group.of("Miscelaneous",
Setting.of("Config file saving delay (ms)", configSavingDelayMs,
"Wait specified number of milliseconds before actually writing config to disk"))));
"Wait specified number of milliseconds before actually writing config to disk"))),
Category.of("Donate", (new DonateTabFx()).getContent()),
Category.of("Help", (new HelpTab()).getContent()));
Region preferencesView = prefs.getView();
prefs.onRestartRequired(this::showRestartRequired);
storage.setPreferences(prefs);

View File

@ -4,46 +4,91 @@ import ctbrec.docs.DocServer;
import ctbrec.ui.DesktopIntegration;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.atomic.AtomicBoolean;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
@Slf4j
public class HelpTab extends Tab {
private boolean serverStarted = false;
public HelpTab() {
setClosable(true);
setClosable(false);
setText("Help");
var openHelp = new Button("Open Help");
Button openHelp = new Button("Open Help");
Button openLog = new Button("Open Log File");
openHelp.setPadding(new Insets(20));
var layout = new BorderPane(openHelp);
BorderPane.setMargin(openHelp, new Insets(20));
openLog.setPadding(new Insets(20));
Label logFilePathLabel = new Label("Log: " + new File("ctbrec.log").getAbsolutePath());
VBox vbox = new VBox();
vbox.setAlignment(Pos.CENTER); // Center align the buttons
vbox.setSpacing(20); // Set a 20 pixel gap between the buttons
vbox.getChildren().addAll(openHelp, openLog, logFilePathLabel);
BorderPane layout = new BorderPane();
// Add the VBox to the center region of the BorderPane
layout.setCenter(vbox);
setContent(layout);
AtomicBoolean started = new AtomicBoolean(false);
openHelp.setOnAction(e -> {
synchronized (started) {
if (!started.get()) {
new Thread(() -> {
try {
DocServer.start(() ->
Platform.runLater(() -> {
started.set(true);
DesktopIntegration.open("http://localhost:5689/docs/index.md");
})
);
} catch (Exception ex) {
log.error("Couldn't start documentation server", ex);
}
}).start();
} else {
DesktopIntegration.open("http://localhost:5689/docs/index.md");
}
if (!serverStarted) {
startDocumentationServer();
} else {
openDocumentationPage();
}
});
openLog.setOnAction(e -> {
File logFile = new File("ctbrec.log");
if (logFile.exists()) {
try {
// Use Runtime.getRuntime().exec() to open the file in a separate process
String osName = System.getProperty("os.name").toLowerCase();
ProcessBuilder pb = null;
if (osName.contains("mac")) {
pb = new ProcessBuilder("open", logFile.getAbsolutePath());
} else if (osName.contains("win")) {
pb = new ProcessBuilder("explorer.exe", logFile.getAbsolutePath());
} else { // Assume it's a Unix/Linux system
pb = new ProcessBuilder("xdg-open", logFile.getAbsolutePath());
}
pb.start();
} catch (IOException ex) {
log.error("Couldn't open log file", ex);
}
);
} else {
log.warn("Log file doesn't exist: {}", logFile.getAbsolutePath());
}
});
}
}
private void startDocumentationServer() {
new Thread(() -> {
try {
DocServer.start(() -> Platform.runLater(() -> {
serverStarted = true;
openDocumentationPage();
}));
} catch (Exception ex) {
log.error("Couldn't start documentation server", ex);
}
}).start();
}
private void openDocumentationPage() {
DesktopIntegration.open("http://localhost:5689/docs/index.md");
}
}