From 4b81bff9ca600f3cdf5221282f56668146a2cf5f Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 16 Aug 2024 10:18:26 +0200 Subject: [PATCH 1/3] fix and dedup code test does not understand shell subcommand syntax --- .../linux/quickaccess/DolphinPlaces.java | 11 ++-------- .../linux/quickaccess/NautilusBookmarks.java | 11 ++-------- .../cryptomator/linux/util/SupportUtil.java | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/cryptomator/linux/util/SupportUtil.java 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/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; + } +} From e298ba59068ab7215f55cfab821f05b6198a32c1 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 16 Aug 2024 10:20:29 +0200 Subject: [PATCH 2/3] simplify dbus-send check --- .../revealpath/DBusSendRevealPathService.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) 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)) { From a2c03530a54fd262ea0fa45b2b338a1449850db2 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Fri, 16 Aug 2024 11:36:10 +0200 Subject: [PATCH 3/3] only support freedesktop autostart, if autostartCmd property is explicitly set --- .../linux/autostart/FreedesktopAutoStartService.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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()); }