os detection

This commit is contained in:
rdavidek 2026-01-25 22:56:59 +01:00
parent 3225f17050
commit 8370e1cf76
4 changed files with 33 additions and 17 deletions

View File

@ -17,13 +17,32 @@ public class MainApp {
public static final String APP_VERSION = "0.0.9";
public enum OS {
WINDOWS, LINUX, MACOS, UNKNOWN
}
public static final OS CURRENT_OS;
static {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win")) {
CURRENT_OS = OS.WINDOWS;
} else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) {
CURRENT_OS = OS.LINUX;
} else if (os.contains("mac")) {
CURRENT_OS = OS.MACOS;
} else {
CURRENT_OS = OS.UNKNOWN;
}
}
public static void main(String[] args) {
// Set application name for X11/Wayland WM_CLASS
System.setProperty("awt.app.name", "cz-kamma-kfmanager-MainApp");
// Use FlatLaf for modern look and better system theme support
try {
if (System.getProperty("os.name").toLowerCase().contains("win")) {
if (CURRENT_OS == OS.WINDOWS) {
// On Windows, use FlatLaf and detect system theme (light/dark)
if (isWindowsDarkMode()) {
FlatDarkLaf.setup();

View File

@ -1,5 +1,6 @@
package cz.kamma.kfmanager.ui;
import cz.kamma.kfmanager.MainApp;
import cz.kamma.kfmanager.model.FileItem;
import javax.swing.*;
@ -468,8 +469,7 @@ public class FilePanel extends JPanel {
driveSet.add(new File(System.getProperty("user.home")));
// On Linux/Unix, add common mount points
String os = System.getProperty("os.name").toLowerCase();
if (!os.contains("win")) {
if (MainApp.CURRENT_OS != MainApp.OS.WINDOWS) {
// Common Linux/Unix mount points
String user = System.getProperty("user.name");

View File

@ -1,5 +1,6 @@
package cz.kamma.kfmanager.ui;
import cz.kamma.kfmanager.MainApp;
import cz.kamma.kfmanager.model.FileItem;
import cz.kamma.kfmanager.config.AppConfig;
import cz.kamma.kfmanager.service.ClipboardService;
@ -1465,12 +1466,11 @@ public class FilePanelTab extends JPanel {
try {
new ProcessBuilder(cmdList).directory(file.getParentFile()).start();
} catch (IOException ex) {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("win")) {
if (MainApp.CURRENT_OS == MainApp.OS.WINDOWS) {
// Try via cmd.exe for Windows shell commands/scripts
new ProcessBuilder("cmd", "/c", trimmedCmd + (hasPlaceholder ? "" : " \"" + fullPath + "\""))
.directory(file.getParentFile()).start();
} else if (osName.contains("linux") || osName.contains("mac")) {
} else if (MainApp.CURRENT_OS == MainApp.OS.LINUX || MainApp.CURRENT_OS == MainApp.OS.MACOS) {
new ProcessBuilder("sh", "-c", trimmedCmd + (hasPlaceholder ? "" : " '" + fullPath + "'"))
.directory(file.getParentFile()).start();
} else {
@ -1668,11 +1668,10 @@ public class FilePanelTab extends JPanel {
setMenuItemEnabled(revealItem, !isParentDir);
revealItem.addActionListener(ae -> {
try {
String os = System.getProperty("os.name").toLowerCase();
File f = item.getFile();
if (os.contains("win")) {
if (MainApp.CURRENT_OS == MainApp.OS.WINDOWS) {
new ProcessBuilder("explorer.exe", "/select,", f.getAbsolutePath()).start();
} else if (os.contains("mac")) {
} else if (MainApp.CURRENT_OS == MainApp.OS.MACOS) {
new ProcessBuilder("open", "-R", f.getAbsolutePath()).start();
} else {
File parent = f.getParentFile();

View File

@ -33,7 +33,7 @@ public class MainWindow extends JFrame {
private Timer autoRefreshTimer;
public MainWindow() {
super("KF Manager v" + MainApp.APP_VERSION);
super("KF Manager v" + MainApp.APP_VERSION + " (" + MainApp.CURRENT_OS + ")");
// Set application icon
loadAppIcon();
@ -2147,13 +2147,12 @@ public class MainWindow extends JFrame {
}
try {
String osName = System.getProperty("os.name").toLowerCase();
ProcessBuilder pb = null;
if (osName.contains("win")) {
if (MainApp.CURRENT_OS == MainApp.OS.WINDOWS) {
// Windows - open cmd.exe
pb = new ProcessBuilder("cmd.exe", "/c", "start", "cmd.exe");
} else if (osName.contains("mac")) {
} else if (MainApp.CURRENT_OS == MainApp.OS.MACOS) {
// macOS
pb = new ProcessBuilder("open", "-a", "Terminal", currentDir.getAbsolutePath());
} else {
@ -2268,12 +2267,11 @@ public class MainWindow extends JFrame {
currentDir = new File(System.getProperty("user.home"));
}
String osName = System.getProperty("os.name").toLowerCase();
try {
String trimmedCmd = command.trim();
// Special case for Windows terminal commands - launch in a new window
if (osName.contains("win")) {
if (MainApp.CURRENT_OS == MainApp.OS.WINDOWS) {
String cmdLower = trimmedCmd.toLowerCase();
if (cmdLower.equals("cmd") || cmdLower.equals("powershell") ||
cmdLower.equals("pwsh") || cmdLower.equals("wt")) {
@ -2305,9 +2303,9 @@ public class MainWindow extends JFrame {
new ProcessBuilder(cmdList).directory(currentDir).start();
} catch (IOException ex) {
// Fallback for different OS: try via shell
if (osName.contains("linux") || osName.contains("mac")) {
if (MainApp.CURRENT_OS == MainApp.OS.LINUX || MainApp.CURRENT_OS == MainApp.OS.MACOS) {
new ProcessBuilder("sh", "-c", command).directory(currentDir).start();
} else if (osName.contains("win")) {
} else if (MainApp.CURRENT_OS == MainApp.OS.WINDOWS) {
new ProcessBuilder("cmd", "/c", command).directory(currentDir).start();
} else {
throw ex;