Skip to content

Commit

Permalink
Merge branch 'develop' into release/1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Aug 16, 2024
2 parents ec5f08f + a2c0353 commit 3bba25c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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)) {
Expand Down
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 3bba25c

Please sign in to comment.