Browse Source

Apply code suggestions

Armin Schrenk 1 year ago
parent
commit
1d6edb8373

+ 2 - 2
src/main/java/module-info.java

@@ -2,7 +2,7 @@ import ch.qos.logback.classic.spi.Configurator;
 import org.cryptomator.common.locationpresets.DropboxMacLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.DropboxWindowsLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.GoogleDriveMacLocationPresetsProvider;
-import org.cryptomator.common.locationpresets.GoogleDriveWindowsLocationPresetsProvider;
+import org.cryptomator.common.locationpresets.GoogleDriveLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.ICloudMacLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.ICloudWindowsLocationPresetsProvider;
 import org.cryptomator.common.locationpresets.LocationPresetsProvider;
@@ -54,7 +54,7 @@ open module org.cryptomator.desktop {
 	provides Configurator with LogbackConfiguratorFactory;
 	provides LocationPresetsProvider with DropboxMacLocationPresetsProvider, //
 			DropboxWindowsLocationPresetsProvider, ICloudMacLocationPresetsProvider, //
-			ICloudWindowsLocationPresetsProvider, GoogleDriveWindowsLocationPresetsProvider, //
+			ICloudWindowsLocationPresetsProvider, GoogleDriveLocationPresetsProvider, //
 			GoogleDriveMacLocationPresetsProvider, PCloudLocationPresetsProvider, //
 			MegaLocationPresetsProvider, OneDriveLocationPresetsProvider, OneDriveWindowsLocationPresetsProvider;
 }

+ 10 - 3
src/main/java/org/cryptomator/common/locationpresets/DropboxMacLocationPresetsProvider.java

@@ -13,16 +13,23 @@ import static org.cryptomator.integrations.common.OperatingSystem.Value.MAC;
 @CheckAvailability
 public final class DropboxMacLocationPresetsProvider implements LocationPresetsProvider {
 
-	private static final Path LOCATION = LocationPresetsProvider.resolveLocation("~/Library/CloudStorage/Dropbox");
+	private static final Path LOCATION1 = LocationPresetsProvider.resolveLocation("~/Library/CloudStorage/Dropbox");
+	private static final Path LOCATION2 = LocationPresetsProvider.resolveLocation("~/Dropbox");
 
 
 	@CheckAvailability
 	public static boolean isPresent() {
-		return Files.isDirectory(LOCATION);
+		return Files.isDirectory(LOCATION1) || Files.isDirectory(LOCATION2);
 	}
 
 	@Override
 	public Stream<LocationPreset> getLocations() {
-		return Stream.of(new LocationPreset("Dropbox", LOCATION));
+		if(Files.isDirectory(LOCATION1)) {
+			return Stream.of(new LocationPreset("Dropbox", LOCATION1));
+		} else if(Files.isDirectory(LOCATION2)) {
+			return Stream.of(new LocationPreset("Dropbox", LOCATION2));
+		} else {
+			return Stream.of();
+		}
 	}
 }

+ 3 - 1
src/main/java/org/cryptomator/common/locationpresets/GoogleDriveWindowsLocationPresetsProvider.java

@@ -7,11 +7,13 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.stream.Stream;
 
+import static org.cryptomator.integrations.common.OperatingSystem.Value.MAC;
 import static org.cryptomator.integrations.common.OperatingSystem.Value.WINDOWS;
 
 @OperatingSystem(WINDOWS)
+@OperatingSystem(MAC)
 @CheckAvailability
-public final class GoogleDriveWindowsLocationPresetsProvider implements LocationPresetsProvider {
+public final class GoogleDriveLocationPresetsProvider implements LocationPresetsProvider {
 
 	private static final Path LOCATION = LocationPresetsProvider.resolveLocation("~/Google Drive");
 

+ 0 - 28
src/main/java/org/cryptomator/common/locationpresets/GoogleDriveMacLocationPresetsProvider.java

@@ -1,28 +0,0 @@
-package org.cryptomator.common.locationpresets;
-
-import org.cryptomator.integrations.common.CheckAvailability;
-import org.cryptomator.integrations.common.OperatingSystem;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.stream.Stream;
-
-import static org.cryptomator.integrations.common.OperatingSystem.Value.MAC;
-
-@OperatingSystem(MAC)
-@CheckAvailability
-public final class GoogleDriveMacLocationPresetsProvider implements LocationPresetsProvider {
-
-	private static final Path LOCATION = LocationPresetsProvider.resolveLocation("~/Google Drive/My Drive");
-
-
-	@CheckAvailability
-	public static boolean isPresent() {
-		return Files.isDirectory(LOCATION);
-	}
-
-	@Override
-	public Stream<LocationPreset> getLocations() {
-		return Stream.of(new LocationPreset("Google Drive", LOCATION));
-	}
-}

+ 2 - 2
src/main/java/org/cryptomator/common/locationpresets/OneDriveWindowsLocationPresetsProvider.java

@@ -76,7 +76,7 @@ public final class OneDriveWindowsLocationPresetsProvider implements LocationPre
 	 * @throws CommandFailedException Thrown when the process exit code is non-zero
 	 */
 	@Blocking
-	static void waitForSuccess(Process process, int timeoutSeconds, String cmdDescription) throws TimeoutException, InterruptedException, CommandFailedException {
+	private static void waitForSuccess(Process process, int timeoutSeconds, String cmdDescription) throws TimeoutException, InterruptedException, CommandFailedException {
 		boolean exited = process.waitFor(timeoutSeconds, TimeUnit.SECONDS);
 		if (!exited) {
 			throw new TimeoutException(cmdDescription + " timed out after " + timeoutSeconds + "s");
@@ -88,7 +88,7 @@ public final class OneDriveWindowsLocationPresetsProvider implements LocationPre
 		}
 	}
 
-	static class CommandFailedException extends Exception {
+	private static class CommandFailedException extends Exception {
 
 		int exitCode;
 		String stdout;