os detection
This commit is contained in:
parent
3225f17050
commit
8370e1cf76
@ -17,13 +17,32 @@ public class MainApp {
|
|||||||
|
|
||||||
public static final String APP_VERSION = "0.0.9";
|
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) {
|
public static void main(String[] args) {
|
||||||
// Set application name for X11/Wayland WM_CLASS
|
// Set application name for X11/Wayland WM_CLASS
|
||||||
System.setProperty("awt.app.name", "cz-kamma-kfmanager-MainApp");
|
System.setProperty("awt.app.name", "cz-kamma-kfmanager-MainApp");
|
||||||
|
|
||||||
// Use FlatLaf for modern look and better system theme support
|
// Use FlatLaf for modern look and better system theme support
|
||||||
try {
|
try {
|
||||||
if (System.getProperty("os.name").toLowerCase().contains("win")) {
|
if (CURRENT_OS == OS.WINDOWS) {
|
||||||
// On Windows, use FlatLaf and detect system theme (light/dark)
|
// On Windows, use FlatLaf and detect system theme (light/dark)
|
||||||
if (isWindowsDarkMode()) {
|
if (isWindowsDarkMode()) {
|
||||||
FlatDarkLaf.setup();
|
FlatDarkLaf.setup();
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package cz.kamma.kfmanager.ui;
|
package cz.kamma.kfmanager.ui;
|
||||||
|
|
||||||
|
import cz.kamma.kfmanager.MainApp;
|
||||||
import cz.kamma.kfmanager.model.FileItem;
|
import cz.kamma.kfmanager.model.FileItem;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -468,8 +469,7 @@ public class FilePanel extends JPanel {
|
|||||||
driveSet.add(new File(System.getProperty("user.home")));
|
driveSet.add(new File(System.getProperty("user.home")));
|
||||||
|
|
||||||
// On Linux/Unix, add common mount points
|
// On Linux/Unix, add common mount points
|
||||||
String os = System.getProperty("os.name").toLowerCase();
|
if (MainApp.CURRENT_OS != MainApp.OS.WINDOWS) {
|
||||||
if (!os.contains("win")) {
|
|
||||||
// Common Linux/Unix mount points
|
// Common Linux/Unix mount points
|
||||||
String user = System.getProperty("user.name");
|
String user = System.getProperty("user.name");
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package cz.kamma.kfmanager.ui;
|
package cz.kamma.kfmanager.ui;
|
||||||
|
|
||||||
|
import cz.kamma.kfmanager.MainApp;
|
||||||
import cz.kamma.kfmanager.model.FileItem;
|
import cz.kamma.kfmanager.model.FileItem;
|
||||||
import cz.kamma.kfmanager.config.AppConfig;
|
import cz.kamma.kfmanager.config.AppConfig;
|
||||||
import cz.kamma.kfmanager.service.ClipboardService;
|
import cz.kamma.kfmanager.service.ClipboardService;
|
||||||
@ -1465,12 +1466,11 @@ public class FilePanelTab extends JPanel {
|
|||||||
try {
|
try {
|
||||||
new ProcessBuilder(cmdList).directory(file.getParentFile()).start();
|
new ProcessBuilder(cmdList).directory(file.getParentFile()).start();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
String osName = System.getProperty("os.name").toLowerCase();
|
if (MainApp.CURRENT_OS == MainApp.OS.WINDOWS) {
|
||||||
if (osName.contains("win")) {
|
|
||||||
// Try via cmd.exe for Windows shell commands/scripts
|
// Try via cmd.exe for Windows shell commands/scripts
|
||||||
new ProcessBuilder("cmd", "/c", trimmedCmd + (hasPlaceholder ? "" : " \"" + fullPath + "\""))
|
new ProcessBuilder("cmd", "/c", trimmedCmd + (hasPlaceholder ? "" : " \"" + fullPath + "\""))
|
||||||
.directory(file.getParentFile()).start();
|
.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 + "'"))
|
new ProcessBuilder("sh", "-c", trimmedCmd + (hasPlaceholder ? "" : " '" + fullPath + "'"))
|
||||||
.directory(file.getParentFile()).start();
|
.directory(file.getParentFile()).start();
|
||||||
} else {
|
} else {
|
||||||
@ -1668,11 +1668,10 @@ public class FilePanelTab extends JPanel {
|
|||||||
setMenuItemEnabled(revealItem, !isParentDir);
|
setMenuItemEnabled(revealItem, !isParentDir);
|
||||||
revealItem.addActionListener(ae -> {
|
revealItem.addActionListener(ae -> {
|
||||||
try {
|
try {
|
||||||
String os = System.getProperty("os.name").toLowerCase();
|
|
||||||
File f = item.getFile();
|
File f = item.getFile();
|
||||||
if (os.contains("win")) {
|
if (MainApp.CURRENT_OS == MainApp.OS.WINDOWS) {
|
||||||
new ProcessBuilder("explorer.exe", "/select,", f.getAbsolutePath()).start();
|
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();
|
new ProcessBuilder("open", "-R", f.getAbsolutePath()).start();
|
||||||
} else {
|
} else {
|
||||||
File parent = f.getParentFile();
|
File parent = f.getParentFile();
|
||||||
|
|||||||
@ -33,7 +33,7 @@ public class MainWindow extends JFrame {
|
|||||||
private Timer autoRefreshTimer;
|
private Timer autoRefreshTimer;
|
||||||
|
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
super("KF Manager v" + MainApp.APP_VERSION);
|
super("KF Manager v" + MainApp.APP_VERSION + " (" + MainApp.CURRENT_OS + ")");
|
||||||
|
|
||||||
// Set application icon
|
// Set application icon
|
||||||
loadAppIcon();
|
loadAppIcon();
|
||||||
@ -2147,13 +2147,12 @@ public class MainWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String osName = System.getProperty("os.name").toLowerCase();
|
|
||||||
ProcessBuilder pb = null;
|
ProcessBuilder pb = null;
|
||||||
|
|
||||||
if (osName.contains("win")) {
|
if (MainApp.CURRENT_OS == MainApp.OS.WINDOWS) {
|
||||||
// Windows - open cmd.exe
|
// Windows - open cmd.exe
|
||||||
pb = new ProcessBuilder("cmd.exe", "/c", "start", "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
|
// macOS
|
||||||
pb = new ProcessBuilder("open", "-a", "Terminal", currentDir.getAbsolutePath());
|
pb = new ProcessBuilder("open", "-a", "Terminal", currentDir.getAbsolutePath());
|
||||||
} else {
|
} else {
|
||||||
@ -2268,12 +2267,11 @@ public class MainWindow extends JFrame {
|
|||||||
currentDir = new File(System.getProperty("user.home"));
|
currentDir = new File(System.getProperty("user.home"));
|
||||||
}
|
}
|
||||||
|
|
||||||
String osName = System.getProperty("os.name").toLowerCase();
|
|
||||||
try {
|
try {
|
||||||
String trimmedCmd = command.trim();
|
String trimmedCmd = command.trim();
|
||||||
|
|
||||||
// Special case for Windows terminal commands - launch in a new window
|
// 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();
|
String cmdLower = trimmedCmd.toLowerCase();
|
||||||
if (cmdLower.equals("cmd") || cmdLower.equals("powershell") ||
|
if (cmdLower.equals("cmd") || cmdLower.equals("powershell") ||
|
||||||
cmdLower.equals("pwsh") || cmdLower.equals("wt")) {
|
cmdLower.equals("pwsh") || cmdLower.equals("wt")) {
|
||||||
@ -2305,9 +2303,9 @@ public class MainWindow extends JFrame {
|
|||||||
new ProcessBuilder(cmdList).directory(currentDir).start();
|
new ProcessBuilder(cmdList).directory(currentDir).start();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
// Fallback for different OS: try via shell
|
// 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();
|
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();
|
new ProcessBuilder("cmd", "/c", command).directory(currentDir).start();
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user