fixed terminal open

This commit is contained in:
Radek Davidek 2026-01-15 11:31:50 +01:00
parent ac13e6504f
commit c132811c0b

View File

@ -1058,7 +1058,7 @@ public class MainWindow extends JFrame {
try { try {
String osName = System.getProperty("os.name").toLowerCase(); String osName = System.getProperty("os.name").toLowerCase();
ProcessBuilder pb; ProcessBuilder pb = null;
if (osName.contains("win")) { if (osName.contains("win")) {
// Windows // Windows
@ -1068,15 +1068,20 @@ public class MainWindow extends JFrame {
pb = new ProcessBuilder("open", "-a", "Terminal", currentDir.getAbsolutePath()); pb = new ProcessBuilder("open", "-a", "Terminal", currentDir.getAbsolutePath());
} else { } else {
// Linux and other Unix-like systems // Linux and other Unix-like systems
// Try common terminal emulators // Try common terminal emulators with working directory arguments
String[] terminals = {"gnome-terminal", "xterm", "konsole", "xfce4-terminal", "mate-terminal"}; String[] terminals = {"gnome-terminal", "konsole", "xfce4-terminal", "mate-terminal", "xterm"};
pb = null;
for (String terminal : terminals) { for (String terminal : terminals) {
try { try {
Process p = Runtime.getRuntime().exec(new String[]{"which", terminal}); Process p = Runtime.getRuntime().exec(new String[]{"which", terminal});
if (p.waitFor() == 0) { if (p.waitFor() == 0) {
if (terminal.equals("gnome-terminal") || terminal.equals("xfce4-terminal") || terminal.equals("mate-terminal")) {
pb = new ProcessBuilder(terminal, "--working-directory=" + currentDir.getAbsolutePath());
} else if (terminal.equals("konsole")) {
pb = new ProcessBuilder(terminal, "--workdir", currentDir.getAbsolutePath());
} else {
pb = new ProcessBuilder(terminal); pb = new ProcessBuilder(terminal);
}
break; break;
} }
} catch (Exception e) { } catch (Exception e) {
@ -1085,13 +1090,15 @@ public class MainWindow extends JFrame {
} }
if (pb == null) { if (pb == null) {
// Fallback to xterm if nothing else works // Fallback to xterm
pb = new ProcessBuilder("xterm"); pb = new ProcessBuilder("xterm");
} }
} }
if (pb != null) {
pb.directory(currentDir); pb.directory(currentDir);
pb.start(); pb.start();
}
} catch (Exception e) { } catch (Exception e) {
JOptionPane.showMessageDialog(this, JOptionPane.showMessageDialog(this,