From 07f4e21c9bb7d4304ee99bf309bbadfdb78a40d7 Mon Sep 17 00:00:00 2001 From: Jafea7 Date: Sat, 3 May 2025 21:56:51 +1000 Subject: [PATCH] Open config dir from Settings->Help --- .../java/ctbrec/ui/settings/SettingsTab.java | 2 +- .../src/main/java/ctbrec/ui/tabs/HelpTab.java | 36 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/settings/SettingsTab.java b/client/src/main/java/ctbrec/ui/settings/SettingsTab.java index 26c0dbb0..64bb98c4 100644 --- a/client/src/main/java/ctbrec/ui/settings/SettingsTab.java +++ b/client/src/main/java/ctbrec/ui/settings/SettingsTab.java @@ -333,7 +333,7 @@ public class SettingsTab extends Tab implements TabSelectionListener { "Use hlsdl to record the live streams. Some features might not work correctly."), Setting.of("hlsdl executable", hlsdlExecutable, "Path to the hlsdl executable"), Setting.of("Log hlsdl output", loghlsdlOutput, "Log hlsdl output to files in the system's temp directory"))), - Category.of("Help", (new HelpTab()).getContent()), + Category.of("Help/Cfg/Log", (new HelpTab()).getContent()), Category.of("Donate", (new DonateTabFx()).getContent())); Region preferencesView = prefs.getView(); prefs.onRestartRequired(this::showRestartRequired); diff --git a/client/src/main/java/ctbrec/ui/tabs/HelpTab.java b/client/src/main/java/ctbrec/ui/tabs/HelpTab.java index 846b36fd..abc39038 100644 --- a/client/src/main/java/ctbrec/ui/tabs/HelpTab.java +++ b/client/src/main/java/ctbrec/ui/tabs/HelpTab.java @@ -1,5 +1,7 @@ package ctbrec.ui.tabs; +import ctbrec.Config; +import ctbrec.OS; import ctbrec.docs.DocServer; import ctbrec.ui.DesktopIntegration; import javafx.application.Platform; @@ -27,15 +29,20 @@ public class HelpTab extends Tab { Button openHelp = new Button("Open Help"); Button openLog = new Button("Open Log File"); + Button openCfg = new Button("Open config dir"); openHelp.setPadding(new Insets(20)); openLog.setPadding(new Insets(20)); - Label logFilePathLabel = new Label("Log: " + new File("ctbrec.log").getAbsolutePath()); + openCfg.setPadding(new Insets(20)); + Label logFilePathLabel = new Label("Log file: " + new File("ctbrec.log").getAbsolutePath()); + File cfgDir = Config.getInstance().getConfigDir(); + String path = (cfgDir != null) ? cfgDir.getAbsolutePath() : "Unknown"; + Label configPathLabel = new Label("Config dir: " + path); 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); - + vbox.getChildren().addAll(openHelp, openCfg, configPathLabel, openLog, logFilePathLabel); + BorderPane layout = new BorderPane(); // Add the VBox to the center region of the BorderPane @@ -73,6 +80,29 @@ public class HelpTab extends Tab { log.warn("Log file doesn't exist: {}", logFile.getAbsolutePath()); } }); + + openCfg.setOnAction(e -> { + File configDir = Config.getInstance().getConfigDir(); + if (configDir.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", configDir.getAbsolutePath()); + } else if (osName.contains("win")) { + pb = new ProcessBuilder("explorer.exe", configDir.getAbsolutePath()); + } else { // Assume it's a Unix/Linux system + pb = new ProcessBuilder("xdg-open", configDir.getAbsolutePath()); + } + pb.start(); + } catch (IOException ex) { + log.error("Couldn't open config dir", ex); + } + } else { + log.warn("Config dir doesn't exist: {}", configDir.getAbsolutePath()); + } + }); } private void startDocumentationServer() {