Skip to content

Commit 4b81bff

Browse files
committed
fix and dedup code
test does not understand shell subcommand syntax
1 parent 91f6839 commit 4b81bff

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/main/java/org/cryptomator/linux/quickaccess/DolphinPlaces.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.cryptomator.integrations.common.Priority;
77
import org.cryptomator.integrations.quickaccess.QuickAccessService;
88
import org.cryptomator.integrations.quickaccess.QuickAccessServiceException;
9+
import org.cryptomator.linux.util.SupportUtil;
910
import org.xml.sax.SAXException;
1011

1112
import javax.xml.XMLConstants;
@@ -160,14 +161,6 @@ private int indexOfEntryOpeningTag(String placesContent, int idIndex) {
160161

161162
@CheckAvailability
162163
public static boolean isSupported() {
163-
try {
164-
var nautilusExistsProc = new ProcessBuilder().command("test", "`command -v dolphin`").start();
165-
if (nautilusExistsProc.waitFor(5000, TimeUnit.MILLISECONDS)) {
166-
return nautilusExistsProc.exitValue() == 0;
167-
}
168-
} catch (IOException | InterruptedException e) {
169-
//NO-OP
170-
}
171-
return false;
164+
return SupportUtil.commandExists("dolphin");
172165
}
173166
}

src/main/java/org/cryptomator/linux/quickaccess/NautilusBookmarks.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.cryptomator.integrations.common.Priority;
77
import org.cryptomator.integrations.quickaccess.QuickAccessService;
88
import org.cryptomator.integrations.quickaccess.QuickAccessServiceException;
9+
import org.cryptomator.linux.util.SupportUtil;
910

1011
import java.io.IOException;
1112
import java.nio.charset.StandardCharsets;
@@ -84,14 +85,6 @@ public void remove() throws QuickAccessServiceException {
8485

8586
@CheckAvailability
8687
public static boolean isSupported() {
87-
try {
88-
var nautilusExistsProc = new ProcessBuilder().command("test", "`command -v nautilus`").start();
89-
if (nautilusExistsProc.waitFor(5000, TimeUnit.MILLISECONDS)) {
90-
return nautilusExistsProc.exitValue() == 0;
91-
}
92-
} catch (IOException | InterruptedException e) {
93-
//NO-OP
94-
}
95-
return false;
88+
return SupportUtil.commandExists("nautilus");
9689
}
9790
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.cryptomator.linux.util;
2+
3+
import java.io.IOException;
4+
import java.util.Objects;
5+
import java.util.concurrent.TimeUnit;
6+
7+
public class SupportUtil {
8+
9+
public static boolean commandExists(String commandName) {
10+
var shell = Objects.requireNonNullElse(System.getenv("SHELL"),"sh");
11+
try {
12+
var cmdExistsProcess = new ProcessBuilder().command(shell, "-c", "command -v " + commandName).start();
13+
if (cmdExistsProcess.waitFor(5000, TimeUnit.MILLISECONDS)) {
14+
return cmdExistsProcess.exitValue() == 0;
15+
}
16+
} catch (IOException | InterruptedException e) {
17+
//NO-OP
18+
}
19+
return false;
20+
}
21+
}

0 commit comments

Comments
 (0)