Skip to content

Commit

Permalink
Merge pull request #49 from cryptomator/feature/clean-up
Browse files Browse the repository at this point in the history
Chores: Remove dependencies and clean up code
  • Loading branch information
infeo committed Nov 30, 2023
2 parents 6c00398 + 0f6a426 commit 9bbe52c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 33 deletions.
13 changes: 0 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
<secret-service.version>2.0.0-alpha</secret-service.version>
<kdewallet.version>1.3.3</kdewallet.version>
<appindicator.version>1.3.6</appindicator.version>
<guava.version>32.1.3-jre</guava.version>
<slf4j.version>2.0.9</slf4j.version>
<commons-lang3.version>3.13.0</commons-lang3.version>

<!-- test dependencies -->
<junit.version>5.10.1</junit.version>
Expand All @@ -67,11 +65,6 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>de.swiesend</groupId>
<artifactId>secret-service</artifactId>
Expand All @@ -82,12 +75,6 @@
<artifactId>kdewallet</artifactId>
<version>${kdewallet.version}</version>
</dependency>
<!-- Apache Commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<!-- Java bindings for appindicator -->
<dependency>
<groupId>org.purejava</groupId>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
module org.cryptomator.integrations.linux {
requires org.cryptomator.integrations.api;
requires org.slf4j;
requires com.google.common;
requires org.apache.commons.lang3;
requires org.freedesktop.dbus;
requires org.purejava.appindicator;
requires org.purejava.kwallet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.cryptomator.linux.keychain;

import com.google.common.base.Preconditions;
import org.cryptomator.integrations.common.OperatingSystem;
import org.cryptomator.integrations.common.Priority;
import org.cryptomator.integrations.keychain.KeychainAccessException;
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
import org.cryptomator.linux.util.CheckUtil;
import org.freedesktop.dbus.connections.impl.DBusConnection;
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder;
import org.freedesktop.dbus.exceptions.DBusConnectionException;
Expand Down Expand Up @@ -49,25 +49,25 @@ public boolean isLocked() {

@Override
public void storePassphrase(String key, String displayName, CharSequence passphrase) throws KeychainAccessException {
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
CheckUtil.checkState(wallet.isPresent(), "Keychain not supported.");
wallet.get().storePassphrase(key, passphrase);
}

@Override
public char[] loadPassphrase(String key) throws KeychainAccessException {
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
CheckUtil.checkState(wallet.isPresent(), "Keychain not supported.");
return wallet.get().loadPassphrase(key);
}

@Override
public void deletePassphrase(String key) throws KeychainAccessException {
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
CheckUtil.checkState(wallet.isPresent(), "Keychain not supported.");
wallet.get().deletePassphrase(key);
}

@Override
public void changePassphrase(String key, String displayName, CharSequence passphrase) throws KeychainAccessException {
Preconditions.checkState(wallet.isPresent(), "Keychain not supported.");
CheckUtil.checkState(wallet.isPresent(), "Keychain not supported.");
wallet.get().changePassphrase(key, passphrase);
}

Expand Down Expand Up @@ -95,11 +95,7 @@ private static DBusConnection getNewConnection() throws DBusException {
} catch (DBusConnectionException | DBusExecutionException de) {
LOG.warn("Connecting to SESSION bus failed.", de);
LOG.warn("Falling back to SYSTEM DBus");
try {
return DBusConnectionBuilder.forSystemBus().build();
} catch (DBusException e) {
throw e;
}
return DBusConnectionBuilder.forSystemBus().build();
}
}

Expand Down Expand Up @@ -144,7 +140,7 @@ public char[] loadPassphrase(String key) throws KeychainAccessException {
} else {
LOG.debug("loadPassphrase: wallet is closed.");
}
return (password.equals("")) ? null : password.toCharArray();
return (password.isEmpty()) ? null : password.toCharArray();
} catch (RuntimeException e) {
throw new KeychainAccessException("Loading the passphrase failed.", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.cryptomator.linux.revealpath;

import com.google.common.base.Preconditions;
import org.cryptomator.integrations.revealpath.RevealFailedException;
import org.cryptomator.integrations.revealpath.RevealPathService;

Expand Down Expand Up @@ -91,7 +90,9 @@ public boolean isSupported() {
* @throws IOException if the Inputer reader on the process output cannot be created
*/
private boolean parseOutputForFileManagerInterface(Process fileManager1Process) throws IOException {
Preconditions.checkState(!fileManager1Process.isAlive());
if( fileManager1Process.isAlive()) {
throw new IllegalArgumentException("Process " + fileManager1Process + " must be terminated to read output.");
}
try (var reader = fileManager1Process.inputReader(StandardCharsets.UTF_8)) {
return reader.lines().map(String::trim).anyMatch(FILEMANAGER1_XML_ELEMENT::equals);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class AppindicatorTrayMenuController implements TrayMenuController {
private static final Arena ARENA = Arena.global();
private MemorySegment indicator;
private MemorySegment menu = gtk_menu_new();
private Optional<String> svgSourcePath;

@CheckAvailability
public static boolean isAvailable() {
Expand All @@ -48,9 +47,9 @@ public void showTrayIcon(Consumer<TrayIconLoader> iconLoader, Runnable runnable,

private void showTrayIconWithSVG(String s) {
try (var arena = Arena.ofConfined()) {
svgSourcePath = Optional.ofNullable(System.getProperty(SVG_SOURCE_PROPERTY));
var svgSourcePath = System.getProperty(SVG_SOURCE_PROPERTY);
// flatpak
if (svgSourcePath.isEmpty()) {
if (svgSourcePath != null) {
indicator = app_indicator_new(arena.allocateUtf8String(APP_INDICATOR_ID),
arena.allocateUtf8String(s),
APP_INDICATOR_CATEGORY_APPLICATION_STATUS());
Expand All @@ -60,7 +59,7 @@ private void showTrayIconWithSVG(String s) {
arena.allocateUtf8String(s),
APP_INDICATOR_CATEGORY_APPLICATION_STATUS(),
// find tray icons theme in mounted AppImage / installed on system by ppa
arena.allocateUtf8String(svgSourcePath.get()));
arena.allocateUtf8String(svgSourcePath));
}
}
}
Expand Down Expand Up @@ -105,7 +104,7 @@ private void addChildren(MemorySegment menu, List<TrayMenuItem> items) {
}
gtk_menu_shell_append(menu, gtkMenuItem);
}
case SeparatorItem separatorItem -> {
case SeparatorItem _ -> {
var gtkSeparator = gtk_menu_item_new();
gtk_menu_shell_append(menu, gtkSeparator);
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/cryptomator/linux/util/CheckUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.cryptomator.linux.util;

public class CheckUtil {


/**
* Ensures the truth of an expression involving the state of the calling instance, but not
* involving any parameters to the calling method.
*
* @param expression a boolean expression
* @param errorMessage the exception message to use if the check fails; will be converted to a
* string using {@link String#valueOf(Object)}
* @throws IllegalStateException if {@code expression} is false
*/
public static void checkState(boolean expression, String errorMessage) {
if (!expression) {
throw new IllegalStateException(errorMessage);
}
}

public static void checkState(boolean expression) {
if (!expression) {
throw new IllegalStateException();
}
}
}

0 comments on commit 9bbe52c

Please sign in to comment.