Skip to content

Commit

Permalink
fix and dedup code
Browse files Browse the repository at this point in the history
test does not understand shell subcommand syntax
  • Loading branch information
infeo committed Aug 16, 2024
1 parent 91f6839 commit 4b81bff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
21 changes: 21 additions & 0 deletions src/main/java/org/cryptomator/linux/util/SupportUtil.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 4b81bff

Please sign in to comment.