diff --git a/src/main/java/org/cryptomator/linux/autostart/FreedesktopAutoStartService.java b/src/main/java/org/cryptomator/linux/autostart/FreedesktopAutoStartService.java index f36a135..43b9cb0 100644 --- a/src/main/java/org/cryptomator/linux/autostart/FreedesktopAutoStartService.java +++ b/src/main/java/org/cryptomator/linux/autostart/FreedesktopAutoStartService.java @@ -44,11 +44,7 @@ public FreedesktopAutoStartService() { var xdgConfigDirString = Objects.requireNonNullElse(System.getenv("XDG_CONFIG_HOME"), System.getProperty("user.home") + "/.config"); this.autostartFile = Path.of(xdgConfigDirString, "autostart", AUTOSTART_FILENAME); - var execValue = System.getProperty(CMD_PROPERTY); - if (execValue == null) { - LOG.debug("JVM property {} not set, using command path", CMD_PROPERTY); - execValue = ProcessHandle.current().info().command().orElse(""); - } + var execValue = System.getProperty(CMD_PROPERTY,""); this.hasExecValue = !execValue.isBlank(); this.content = CONTENT_TEMPLATE.formatted(execValue, this.getClass().getName()); } diff --git a/src/main/java/org/cryptomator/linux/quickaccess/DolphinPlaces.java b/src/main/java/org/cryptomator/linux/quickaccess/DolphinPlaces.java index 74e268f..8c127b5 100644 --- a/src/main/java/org/cryptomator/linux/quickaccess/DolphinPlaces.java +++ b/src/main/java/org/cryptomator/linux/quickaccess/DolphinPlaces.java @@ -6,6 +6,7 @@ import org.cryptomator.integrations.common.Priority; import org.cryptomator.integrations.quickaccess.QuickAccessService; import org.cryptomator.integrations.quickaccess.QuickAccessServiceException; +import org.cryptomator.linux.util.SupportUtil; import org.xml.sax.SAXException; import javax.xml.XMLConstants; @@ -160,14 +161,6 @@ private int indexOfEntryOpeningTag(String placesContent, int idIndex) { @CheckAvailability public static boolean isSupported() { - try { - var nautilusExistsProc = new ProcessBuilder().command("test", "`command -v dolphin`").start(); - if (nautilusExistsProc.waitFor(5000, TimeUnit.MILLISECONDS)) { - return nautilusExistsProc.exitValue() == 0; - } - } catch (IOException | InterruptedException e) { - //NO-OP - } - return false; + return SupportUtil.commandExists("dolphin"); } } diff --git a/src/main/java/org/cryptomator/linux/quickaccess/NautilusBookmarks.java b/src/main/java/org/cryptomator/linux/quickaccess/NautilusBookmarks.java index 8013e34..c05ed73 100644 --- a/src/main/java/org/cryptomator/linux/quickaccess/NautilusBookmarks.java +++ b/src/main/java/org/cryptomator/linux/quickaccess/NautilusBookmarks.java @@ -6,6 +6,7 @@ import org.cryptomator.integrations.common.Priority; import org.cryptomator.integrations.quickaccess.QuickAccessService; import org.cryptomator.integrations.quickaccess.QuickAccessServiceException; +import org.cryptomator.linux.util.SupportUtil; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -84,14 +85,6 @@ public void remove() throws QuickAccessServiceException { @CheckAvailability public static boolean isSupported() { - try { - var nautilusExistsProc = new ProcessBuilder().command("test", "`command -v nautilus`").start(); - if (nautilusExistsProc.waitFor(5000, TimeUnit.MILLISECONDS)) { - return nautilusExistsProc.exitValue() == 0; - } - } catch (IOException | InterruptedException e) { - //NO-OP - } - return false; + return SupportUtil.commandExists("nautilus"); } } diff --git a/src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java b/src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java index 39529ff..be39d6b 100644 --- a/src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java +++ b/src/main/java/org/cryptomator/linux/revealpath/DBusSendRevealPathService.java @@ -11,7 +11,6 @@ import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.Arrays; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -60,20 +59,10 @@ public void reveal(Path path) throws RevealFailedException { @Override public boolean isSupported() { - CountDownLatch waitBarrier = new CountDownLatch(2); - ProcessBuilder dbusSendExistsBuilder = new ProcessBuilder().command("test", " `command -v dbus-send`"); - ProcessBuilder fileManager1ExistsBuilder = createFileManager1Check(); - try { - var dbusSendExists = dbusSendExistsBuilder.start(); - dbusSendExists.onExit().thenRun(waitBarrier::countDown); - var fileManager1Exists = fileManager1ExistsBuilder.start(); - fileManager1Exists.onExit().thenRun(waitBarrier::countDown); - - if (waitBarrier.await(TIMEOUT_THRESHOLD, TimeUnit.MILLISECONDS)) { - if (dbusSendExists.exitValue() == 0 && fileManager1Exists.exitValue() == 0) { - return parseOutputForFileManagerInterface(fileManager1Exists); - } + var fileManager1Exists = createFileManager1Check().start(); + if (fileManager1Exists.waitFor(TIMEOUT_THRESHOLD, TimeUnit.MILLISECONDS) && fileManager1Exists.exitValue() == 0) { + return parseOutputForFileManagerInterface(fileManager1Exists); } } catch (IOException | InterruptedException e) { //NO-OP @@ -90,7 +79,7 @@ public boolean isSupported() { * @throws IOException if the Inputer reader on the process output cannot be created */ private boolean parseOutputForFileManagerInterface(Process fileManager1Process) throws IOException { - if( fileManager1Process.isAlive()) { + if (fileManager1Process.isAlive()) { throw new IllegalArgumentException("Process " + fileManager1Process + " must be terminated to read output."); } try (var reader = fileManager1Process.inputReader(StandardCharsets.UTF_8)) { diff --git a/src/main/java/org/cryptomator/linux/util/SupportUtil.java b/src/main/java/org/cryptomator/linux/util/SupportUtil.java new file mode 100644 index 0000000..5c022d9 --- /dev/null +++ b/src/main/java/org/cryptomator/linux/util/SupportUtil.java @@ -0,0 +1,21 @@ +package org.cryptomator.linux.util; + +import java.io.IOException; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +public class SupportUtil { + + public static boolean commandExists(String commandName) { + var shell = Objects.requireNonNullElse(System.getenv("SHELL"),"sh"); + try { + var cmdExistsProcess = new ProcessBuilder().command(shell, "-c", "command -v " + commandName).start(); + if (cmdExistsProcess.waitFor(5000, TimeUnit.MILLISECONDS)) { + return cmdExistsProcess.exitValue() == 0; + } + } catch (IOException | InterruptedException e) { + //NO-OP + } + return false; + } +}